Linq To SQL 附加/刷新实体对象
- 作者: 我是养父
- 来源: 51数据库
- 2022-12-15
问题描述
在 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?
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
