实体框架4.0-EF-在图表中很好地映射了多对多关系 [英] Entity Framework 4.0 - EF - maps many-to-many relationships too well in the diagram

查看:59
本文介绍了实体框架4.0-EF-在图表中很好地映射了多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我刚刚建立了我的第一个EF项目,但是我对EF术语的了解还不够.我习惯于使用Linq-to-SQL作为避免SQL查询的一种方式,并且它与我使用的某些WCF Web服务一起使用时效果很好.所有这些都在Microsoft Visual Studio 2010中实现.

Sorry I don't speak EF lingo that well, having just set up my first EF project. I'm used to working with Linq-to-SQL as a way of avoiding SQL queries, and it worked well with some WCF web services I used. All this in Microsoft Visual Studio 2010.

现在在这种背景下,我使用Servr创建了一个数据库,该数据库的表A和B与表C具有多对多关系.由于在数据库理论中这样做是违法的,因此我按原样建立了一个链接表众所周知.它们中的两个:一个称为A_C,另一个称为B_C,每个都有一个分别来自表A和B的外键(1到很多).然后,我将表C和这两个链接表链接在一起,并且这些链接表都从C接收了外键.所以现在我可以了.

Now with that background, I created a database using Servr that has Tables A and B in a many to many relationship with Table C. Since it is illegal to do this in database theory, I set up a linking table, as is well known. Two of them: one called A_C, and the other called B_C, each having a foreign key (1 to many) from tables A and B, respectively. Then I linked table C t both these linking tables, with these linking tables receiving a foreign key from C. So now I am OK I thought.

因此,我使用实体数据模型向导"创建了ADO.NET实体数据模型,选择了来自现有数据库"选项,然后单击按钮.令我感到惊讶,and恼,震惊和敬畏的是,我只看到了三张桌子:A,B和C!没有任何链接表.他们在开玩笑吗?

So I create an ADO.NET entity data model, using the Entity Data Model Wizard, I picked the option "from an existing database", and clicked the buttons. Much to my surprise, and chagrin, and shock and awe, I saw ONLY THREE TABLES: A, B and C! No linking tables whatsoever. Are they kidding me?

考虑一下.运行EF的引擎发现表A和B与表C具有多对多"关系.在.edmx文件的架构图中,A,B和C之间显示星号,完全符合预期

Think about this for a moment. The engine that runs the EF figured out that tables A and B share a "many-to-many" relationship with Table C. In the schema diagram of the .edmx file there is show asterisks between A,B and C, exactly as expected.

SCHEMA中未显示任何链接表!什么?我想不显示链接表是很合逻辑的...但是出乎意料.

BUT NO LINKING TABLES ARE SHOWN IN THE SCHEMA! What? It's very logical I suppose not to show the linking tables...but unexpected.

对于曾经做过多对多表关系的任何人来说,这是您的经验吗?

Is this your experience, for anybody who has ever done many-to-many table relationships?

顺便说一句,在按下发送"键之前,我对EF 4.0进行了大量研究,发现它似乎还在进行中.我可能会陷入很多陷阱.例如,我打算将其部署在WCF REST解决方案中,该解决方案使用与SQL Server数据库一起使用的Web方法.过去我曾经使用过Linq-to-SQL,现在我会谨慎地尝试使用Linq-to-Entities.

BTW, before I hit the Send key, I did a lot of research on EF 4.0, and I find it is a work in progress it seems. Lots of pitfalls, that I will probably fall into. For example, I intend to deploy this in a WCF REST solution that uses web methods that work with a SQL Server database. In the past I've used Linq-to-SQL and now I am going to try, guardedly, to use Linq-to-Entities.

推荐答案

这正是应该发生的情况.并且所有三个表都将正确更新.

That is exactly what is supposed to happen. And all three tables will be updated correctly.

这篇关于实体框架4.0-EF-在图表中很好地映射了多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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