ChangeSet不捕获对实体对象的更改 [英] ChangeSet doesn't capture changes to entity objects
问题描述
亲爱的论坛成员
我已成功使用LINQ to SQL和SQLCE数据库一段时间,但现在遇到的问题是对实体对象所做的更改不会保存到父级数据库。 代码的相关位如下。
与一个名为ServerAppTemplate的数据库有关,它有一个名为ServerSettings的表
在类定义之外:
受保护
ServerAppTemplate serverDataContext =
null ;
受保护
IQueryable < ServerSetting >
serverSettingsEntitiesSequence = null ;
受保护
ServerSetting serverSettingLine =
null ;
在班级的各种方法中:
serverDataContext = new
ServerAppTemplate (serverConnectionString);
serverSettingsEntitiesSequence
=
来自 eachLine
在S erverDataContext.ServerSettings
选择 eachLine;
serverSettingLine
=(
来自 行
serverSettingsEntitiesSequence
选择 line).SingleOrDefault< ServerSetting >();
在此阶段,可以确认serverSettingLine反映父数据库的内容。
现在,我修改一个字段的内容:
serverSettingLine.AdminContact = newAdminContact;
但是,此更改不会出现在changeSet中,也不会在我调用
时持久保存到数据库中span style ="font-size:x-small">
serverDataContext.SubmitChanges()
我在使用SQL Server Management Studio或DataPort控制台创建原始数据库时尝试过这种方法;在这两种情况下,实体类都是由SQL metal生成的。
我是还尝试设置 serverDataContext.ObjectTrackingEnabled =
true ;
还有其他人遇到过这个问题吗?我是傻瓜吗?我会很感激任何建议。
您是否正在检查正确的数据库文件 - 请检查您的bin / debug文件夹。
请参阅:
http://dean-o.blogspot.com/2010/03/mind-your-copy-to-output-directory.html 跨度>
Dear Forum members
I've been using LINQ to SQL with SQLCE databases successfully for a while, but am now encountering a problem whereby changes made to an entity object aren't being saved to the parent database. The relevant bits of code are as follows. They relate to a DB called ServerAppTemplate which has a table named ServerSettings
Outside the class definition:
protected ServerAppTemplate serverDataContext = null;
protected IQueryable<ServerSetting> serverSettingsEntitiesSequence = null;
protected ServerSetting serverSettingLine = null;
Within various methods of the class:
serverDataContext = new ServerAppTemplate(serverConnectionString);
serverSettingsEntitiesSequence
=
from eachLine in ServerDataContext.ServerSettings
select eachLine;
serverSettingLine
= (
from line in serverSettingsEntitiesSequence
select line).SingleOrDefault<ServerSetting>();
At this stage, it is possible to confirm that serverSettingLine reflects the contents of the parent database.
Now, I modify the contents of one field:
serverSettingLine.AdminContact = newAdminContact;
However, this change does not appear in the changeSet, nor is it persisted to the database when I call
serverDataContext.SubmitChanges()
I've tried this when creating the original database with either SQL Server Management Studio or DataPort Console; in both cases, the entity class was generated by SQL metal.
I've also tried setting serverDataContext.ObjectTrackingEnabled = true;
Has anyone else encountered this problem? Am I being stupid? I would be grateful for any advice, please.
Are you checking in the correct database file - check your bin/debug folder.
See this:
http://dean-o.blogspot.com/2010/03/mind-your-copy-to-output-directory.html
这篇关于ChangeSet不捕获对实体对象的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!