强制EF以N-M关系创建中间表 [英] Force EF to create middle table in N-M relationship

查看:130
本文介绍了强制EF以N-M关系创建中间表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须拥有NM关系的实体,这种关系变成两个表E / R模型之间的中间表。

I have to entities with a N-M relationship, that relationship becomes in a middle table between two table E/R model.

在此表具有更多属性之前,但现在它只有来自其他表的id´ s因此EF并不急于显示该表。我的问题是我有很多代码引用该表,我需要知道如何强制EF创建中间表,尽管它和急性; s
不必要

Before this table had more atributes but now it only has id´s from other tables so EF doesn´t show that table. My problem is i have a lot code referecing that table and i need to know how to force to EF creates the middle table despite of it´s unnecessary .

其他解决方案是在表格中添加一个新的属性,但在这种情况下,它不会被允许使用。

Other solution would be add a new atribute to table but in this case it´s not allowed.

 

谢谢。

推荐答案

Hello Jorge,

Hello Jorge,

 

欢迎来到MSDN论坛,感谢您在此发帖。

Welcome to the MSDN Forum and thanks for posting here.

根据您的描述,我认为这很难,并且 不必要这样做。首先,如果从数据库生成代码,要创建中间表对象,数据库中必须有一个中间表。其次,如果我们首先使用模型
或代码,我们还创建中间表模型或者编写一些代码来创建中间表,然后,可以创建中间表。

According to your description, I think it's really hard and unnecessary to do that. First, if you generate code from database, to create the mid-table object, there must be a mid-table in the database. Second, if we use the model first or code first, we also create mid-table model or write some codes to create mid-table, then, the mid-table could be created.

像这篇文章所说:

http://blogs.msdn.com/b/alexj/archive/2008/02/26/associations -with-payloads-closing-the-loop.aspx

我希望这可以帮到你。

 

祝你有愉快的一天,


这篇关于强制EF以N-M关系创建中间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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