在 Linq To Sql 中,当更新我的实体之一 Faculty 时,我正在创建 Faculty 对象的一个新实例,然后使用用户提供的值初始化一些属性.>
如果我将这个新对象附加到实体集并提交更改,我没有设置的属性将采用它们的任何数据类型的默认值.
如何刷新新对象,使已设置的属性保持其值,而未设置的属性从数据库中获取值?
谢谢
你尝试了吗
context.Refresh(RefreshMode.OverwriteCurrentValues,faculty);
提交更改后,context 是您的 linq2sql 数据上下文,faculty 是您要刷新的实体吗?
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?
Thanks
Did you try
context.Refresh(RefreshMode.OverwriteCurrentValues, faculty);
after submit changes where context is your linq2sql datacontext and faculty is the entity you want to refresh?
这篇关于Linq To SQL 附加/刷新实体对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
LINQ to SQL:如何在不检索整个实体的情况下更新唯LINQ to SQL: how to update the only field without retrieving whole entity(LINQ to SQL:如何在不检索整个实体的情况下更新唯一字段)
string1 >= string2 未在 Linq to SQL 中实现,有什string1 gt;= string2 not implemented in Linq to SQL, any workaround?(string1 gt;= string2 未在 Linq to SQL 中实现,有什么解决方法吗?)
如何在条件下使用 RemoveAll 删除列表中的多个项目How to Remove multiple items in List using RemoveAll on condition?(如何在条件下使用 RemoveAll 删除列表中的多个项目?)
转换表达式树Convert Expression trees(转换表达式树)
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“ClientCannot insert explicit value for identity column in table #39;ClientDetails#39; when IDENTITY_INSERT is set to OFF(当 IDENTITY_INSERT 设置为 OFF 时,
Linq 独特的 &最大限度Linq distinct amp; max(Linq 独特的 amp;最大限度)