在 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模板网!