我有一个数据库,其中有一个名为m_AttentionFlags的表,它引用了m_PermissionCollections中的主键。我从中构建了一个EntityFramework模型并创建了一个DomainService。
现在在客户端上使用RIA我已经在控件初始化时将标志加载到本地上下文中:
var query = _context.GetM_AttentionFlagQuery();
_context.Load(query, OnGetM_AttentionFlag, null);
然后我连接了一个按钮,将m_PermissionCollection添加到选定的m_AttentionFlag。
if (lstSelected.SelectedItem != null) {
if (!(lstSelected.SelectedItem is m_AttentionFlag))
{
return;
}
m_AttentionFlag flag = lstSelected.SelectedItem as m_AttentionFlag;
m_PermissionCollection coll = new m_PermissionCollection(); //**
flag.m_PermissionCollections = coll; //**
_context.SubmitChanges();
}
奇怪的是,这会导致插入行为:使用相关的m_PermissionCollection将具有相同字段值的附加m_AttentionFlag添加到数据库中;原始文件保持不变,其m_PermissionCollections字段不受影响。 有趣的是,如果您删除标记为**的行并替换为m_AttentionFlag上的简单公共属性的更新,例如flag.Description =“new description”,更新按预期进行。
DomainService方法是向导生成的默认方法,唯一感兴趣的是更改m_AttentionFlag上的m_PermissionCollections字段会将项目上的EntityState更改为添加到服务器时。
我在RIA服务论坛上问过这个问题,一位成员建议我查找多个DomainContext实例,但_context成员只创建一次,这里列出的代码几乎是各种不生成的代码视觉工作室工具。关于这里发生了什么的任何想法?
非常感谢。
史蒂夫
答案 0 :(得分:0)
事实证明问题在于VS2010提供的默认DomainService实现和RIA服务预览。
问题详述如下:
http://www.riaservicesblog.net/Blog/post/Bug-in-the-Create-DomainService-wizard.aspx