开发者

Entity Framework mapping to service object

开发者 https://www.devze.com 2023-03-09 15:38 出处:网络
I\'m experimenting with EF (4.0) and are a little stuck with the following problem. I have a table A which has 5 relat开发者_开发技巧ions to a table B, so lets call them BLink1 tot BLink 5.

I'm experimenting with EF (4.0) and are a little stuck with the following problem.

I have a table A which has 5 relat开发者_开发技巧ions to a table B, so lets call them BLink1 tot BLink 5. The problem is that the PK in table B is a composed key of 5 fields... so creating a direct link between A and B would result in 25 fields in the table. What we did is introduced a new table A_B between A and B which will provide a mapping from the composite key to a single value. So in A we can then create 5 relations to A_B on this new field. This new field is the PK of table A_B.

What I would like to do in EF (designer or raw XML) is create a logical model with 2 entities; A and B where A has 5 navigational properties to B. EF should be smart enough to go through A_B to get from A to B or vice versa. Also when assigning 1 of the 5 relations on A to point to a specific B, EF should be smart enough to create an entry in the table A_B because the new surrogate key for B is just a concat of these 5 fields with underscores or so between them...

A (0) --> (0..1) A_B (0..1) --> (1) B

PK A_B = B_ID1 + "_" + B_ID2 + "_" + B_ID3 + "_" + B_ID4 + "_" + B_ID5

Hope it's clear... Is this possible with EF?

Kind regards, Dwight

0

精彩评论

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

关注公众号