开发者

Why Do Some Related Entities Persist and Not Others in RIA Services?

I'm having a lot of troubles with RIA Services. I'm really wondering if it's worth the hassle at all. The problem I have now is similar to other problems: related entities. Let's say I have a class, Foo. Foo has two related entities, Bar and Fighter.

If I'm working on a new Foo, foo, and I want to add something to the Bars collection, it works just fine. Like:

foo.Bars.Add(new Bar{A=a, B=b});

But when I try to add a Fighter, it doesn't work:

foo.Fighters.Add(new Fighter{C=c,D=d});

I've been all around the interwebz looking for the solution. I've found the suggestions to use the [Include] attribute and the [Associated] attribute as well. Both have worked in some cases. But they're not working in this case and I have zero clue why. I've deleted and re-created my EDMX and my DomainService because someone suggested it, but it isn't working.

So what is wrong and what other information do you need to help me out? When I say try to add a Fighter to my foo.Fighters collection, it's n开发者_如何学Pythonot persisting the add. I will note that I'm trying to add an existing Fighter in my specific example, not a new Fighter, if that helps/gives clues.

If you need information or real code samples, I'll be happy to oblige. Thanks in advance to all that try to help.


A number of things to check and confirm

  1. The Fighter table has a foreign key defined in the database.
  2. Use [Association], [Include], and [Composition] attributes. Association defines the relationship. Include instructs the server to send the instance or contents of the collection to the client, if populated. Composition instructs WCF RIA to track changes to the collection and send them back to the server.
  3. Ensure you are calling context.SubmitChanges() after all the adds in Silverlight.
  4. Ensure you have an insert method on your DomainService.

Maybe one or more of these will help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜