LINQ to SQL的安装/刷新实体对象实体、对象、LINQ、to

2023-09-04 00:31:57 作者:烟火很不一般

在LINQ to SQL中,更新我的实体之一时,教员,我创建了学院对象的新实例,然后初始化的部分的属性与用户提供的值。

In Linq To Sql, when updating one of my entities, Faculty, I am creating a new instance of the Faculty object, then initializing some of the properties with values supplied by the user.

如果我重视这个新对象的实体集,并提交变更,我并没有设置采取的任何数据类型,它们的默认值。属性

If I attach this new object to the entity set, and submit changes, the properties that I didn't set take on the default value of whatever datatype they are.

我怎样才能刷新新的对象,这样已经设置保持其值的属性和尚未设置从数据库中获取值的属性?

How can I refresh the new object so that the properties that have been set keep their values and the properties that haven't been set get the values from the database?

感谢

推荐答案

你尝试

context.Refresh(RefreshMode.OverwriteCurrentValues​​,教师);

在提交更改其中上下文是LINQ2SQL的DataContext和教师是要刷新的实体?

after submit changes where context is your linq2sql datacontext and faculty is the entity you want to refresh?