Linq To SQL 附加/刷新实体对象 [英] Linq To SQL Attach/Refresh Entity Object

查看:17
本文介绍了Linq To SQL 附加/刷新实体对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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 附加/刷新实体对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆