LINQ to SQL的安装/刷新实体对象 [英] Linq To SQL Attach/Refresh Entity Object
问题描述
在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?
这篇关于LINQ to SQL的安装/刷新实体对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!