开发者

Entity Framework 4 & WCF Data Service: N:M mapping

I have three tables in my database: An A table, a B table, and a many-to-many ABMapping table. For simplicity, A and B are keyed with identity columns; ABMapping has just two columns: AId and BId.

I built an Entity Framework 4 model from this, and it did correctly identify the N:M mapping between A and B. I then built a WCF Data Service based on this EF model.

I'm trying to consume this WCF Data Service. Unfortunately, I can't figure out how to get a mapping between As and Bs to map back to the database. I've tried something like this:

A a = new A();
B b = new B();
a.Bs.Add(b);
connection.SaveChanges();

B开发者_StackOverflowut this doesn't seem to have worked. Any clues? What am I missing?


You need to do the following:

A a = new A();
B b = new B();

connection.AddObject("ASet", a);
// if you have the generated code, you can use the helper method generated
// on the context - something like connection.AddToASet(a);

connection.AddRelatedObject(a, "Bs", b);
connection.SaveChanges();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜