问题描述
在 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?