如何在Entity Framework 4 Entitydesigner中正确设置两个对象之间的关联? [英] How do I correctly set an association between two objects in the Entity Framework 4 Entitydesigner?

查看:152
本文介绍了如何在Entity Framework 4 Entitydesigner中正确设置两个对象之间的关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个新项目,我试图先创建我的业务类,然后再创建真正的数据库表。因此我正在使用Entity Framework 4 Designer。 A创建了一个新的ADO.Net实体数据模型文件,扩展名为.edmx。

For a new project I'm trying to create my business classes first and create the real database tables later. Therefore I'm using the Entity Framework 4 Designer. A created a new "ADO.Net Entity Data model" file, with the extension .edmx.

我创建了两个实体:

I created two Entities:

我想添加一个1到nc关系产品 - >集团。如果我先创建MSSQL数据库,我将添加一个列IDGroup到表产品,并将Product.IDGroup引用到Group.IDGroup。据我所见,如果我在产品实体中添加一个名为IDGroup的新属性,那么我不能在设计器中添加这样的关联。

I want to add a 1 to nc relation between Product -> Group. If I'd created the MSSQL database first, I would have added a column IDGroup to the Table Product and referenced Product.IDGroup to Group.IDGroup. As far as I can see, I can't add such association in the designer if I add a new Property called IDGroup to the Product Entity

这是我如何添加映射:

This is how I add the mapping:

其中结果为:

Which results in:

现在这个问题的部分是:如果我从现有的MSSQL数据库添加两个表到edmx文件,我将得到编译错误:

Now the part what this question is about: If I add two tables from an existing MSSQL database to the edmx file, I'll get the compile error:

Error 3027: No mapping specified for the following EntitySet/AssociationSet - GroupSet, ProductSet

这个错误是什么意思,我该怎么办来解决这个问题?
如果我删除这两个表,我会收到一个警告:

What does that error mean and what must I do to fix this? If I delete those two tables, I'll receive a warning instead:

Error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer myContainer.

有些事告诉我,我做错了这只是基本的东西。我如何做到这一点?

Something tells me, I'm doing this all wrong and this is just basic stuff. How can I do it right?

推荐答案

当我Googled它(我打你的问题)。

I just ran into this myself & when I Googled it (I hit your question).

我可以双击设计器中的行(关联行)。填写属性在那里,我得到它的工作。

I was able to double click on the line (association line) in the designer. Fill in the properties there and I got it working.

我也不得不关闭VS并重新打开它,以获得一些报告的错误消失...

I also had to close VS and re-open it to get some of the errors reported to go away...

不能说这是正确的答案 - 只是摸索着,似乎得到结果。

Can't say this is the correct answer - just fumbling around and seeming to get results.

这篇关于如何在Entity Framework 4 Entitydesigner中正确设置两个对象之间的关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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