自我跟踪实体 - (导航属性)接受更改无法继续,因为对象的键值与ObjectStateManager中的另一个对象冲突 [英] Self Tracking Entities - (Navigation Property) Accept Changes cannot continue because the object's key values conflict with another object in the ObjectStateManager

查看:65
本文介绍了自我跟踪实体 - (导航属性)接受更改无法继续,因为对象的键值与ObjectStateManager中的另一个对象冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到导航属性问题...

I'm having problem with Navigation properties ...

我写了这个简短的脚本。 如果运行两次,它将失败,并显示错误消息:"Accept Changes无法继续,因为对象的键值与ObjectStateManager中的另一个对象冲突"。

I have written this short script.  If ran twice, it fails with the error message: "Accept Changes cannot continue because the object's key values conflict with another object in the ObjectStateManager".

我已将其隔离到导航财产获分配相同的价值。 我注意到如果我改变了价值,它就会很好。

I have isolated it down to the Navigation Property getting assigned with the same value.  I noticed that if I changed the value, it goes through just fine.

我现在已经把头发拉了几天......但仍然无法弄清楚原因。 ..我很感激任何帮助人..

I'd been pulling my hair for a couple of days now .. and still can't figure out why ... I'd appreciate any help guys ..

谢谢!

 

客户 - side代码:

Client-side Code:

命名空间

 

 

ConsoleApplication1

ConsoleApplication1

{

 

 

class
程序

{

 

 

静态
void
Main(
string []
args)

static void Main(string[] args)

{

 

 

期刊
journal;

Journal journal;

 

 

JournalType
journalType;

JournalType journalType;

 

 

使用
Service1Client
service =

Service1Clie nt ())
{

using (Service1Client service = new Service1Client()) {

journal = service.GetJournal();

journal = service.GetJournal();

journalType = service .GetJournalTypes()。Last();

journalType = service.GetJournalTypes().Last();

}

 

 

journal.JournalType = journalType;

journal.JournalType = journalType;

 

 

使用
Service1Client
service =

Service1Clie nt ())
{

using (Service1Client service = new Service1Client()) {

service.Update(journal);

service.Update(journal);

}

}

}

}

Serverside代码

Serverside Code

public

 

 

期刊
GetJournal(){

Journal GetJournal() {

 

 

使用
<跨度风格= "字体家庭:索拉;颜色:#2b91af;字体大小:X-小"> AgilityEntities
context =

AgilityEnti领带 ())
{

using (AgilityEntities context = new AgilityEntities()) {

 

 

期刊
journal = context.Journals.First();

Journal journal = context.Journals.First();

context.LoadProperty(journal,j => j.JournalType);

context.LoadProperty(journal, j => j.JournalType);

 

 

返回
journal;

return journal;

}

}

 

 

public
列表 < JournalType >
GetJournalTypes(){

public List<JournalType> GetJournalTypes() {

 

 

使用
AgilityEntities
context =

AgilityEnti领带 ())
{

using (AgilityEntities context = new AgilityEntities()) {

 

 

返回
context.JournalTypes.ToList();

return context.JournalTypes.ToList();

}

}

 

 

public
void
更新(
Journal
Journal){

public void Update(Journal Journal) {

 

 

使用
AgilityEntities
context =

AgilityEnti领带 ())
{

using (AgilityEntities context = new AgilityEntities()) {

 

 

尝试
{

try {

context.Journals.ApplyChanges(Journal);

context.Journals.ApplyChanges(Journal);

context.SaveChanges() ;

context.SaveChanges();

Journal.AcceptChanges();

Journal.AcceptChanges();

}

 

 

< span style ="font-family:Consolas;颜色:#0000FF; font-size:x-small"> catch
例外
ex){

catch (Exception ex) {

 

 

throw
new
FaultException (ex.Message
+
""
+ ex.InnerException);

throw new FaultException(ex.Message + " " + ex.InnerException);

}

}

}

推荐答案

我是面对同样的错误。如果我找到了什么,我会分享它
I'm facing the same error. If I find something, I will share it


这篇关于自我跟踪实体 - (导航属性)接受更改无法继续,因为对象的键值与ObjectStateManager中的另一个对象冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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