How to properly establish the relationship between two objects in Entity Framework 4 Entitydesigner?

For a new project, I first create my business classes and create real database tables later. Therefore, I use the constructor of Entity Framework 4. A new ADO.Net Entity Data model file is created with the extension .edmx.

I created two entities:
alt text

I want to add a 1 to nc relationship between Product -> Group. If I first created the MSSQL database, I would add an IDG column group to the table product and refer to Product.IDGroup on Group.IDGroup. As far as I can tell, I cannot add such an association to the constructor if I add a new IDGroup property to the product object

This is how I add the mapping: alt text

As a result:
alt text

Now about what this question consists of: if I add two tables from an existing MSSQL database to the edmx file, I get a compilation error:

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

What does this error mean and what should I do to fix it? If I delete these two tables, I will get 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 it all wrong, and it's just basic stuff. How can I do it right?

+53
c # entity-framework-4
Sep 13 '10 at 13:04 on
source share
8 answers

I just stumbled upon it myself, and when I figured it out (I answered your question).

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

I also had to close VS and reopen it so that some of the error messages disappear ...

I canโ€™t say that this is the right answer - just mess around and seem to get results.

+85
Sep 13 2018-10-18
source share

Something that is easy to miss is Create a database from the model . As far as I understand, this needs to be run after every change made to the .edmx database.

This simple mistake happened to me and led to disappointment in a few minutes =)

+9
Mar 29 '12 at 13:55
source share

I got this error when I generated a model from a database using the ADO.Net DBContext Generator under VS2010 SP1 with EF4.1 installed. The database I used did not have any referential integrity between the primary and foreign key fields.

The solution was to double-click on the association line that brings up the Referential Contstrainst dialog box. Then I set the Principal field as a table with a primary key, Dependent as a table with a foreign key, set the names of foreign keys in the drop-down list and click OK.

Then the compiled code, and I was able to work with objects using var foreign = DBContext.Primary.First (). Foreign etc.

Steve

+6
May 09 '11 at 14:50
source share

I had the same error, and one configuration bit that the Add Association dialog box did not help me set was the Reference Constraint property. As soon as I set this up, I rebuilt the solution and everything was cool.

+3
May 05 '11 at 1:14
source share

I had this error when I removed the association from the model diagram, but the connection remains in the underlying XML in .edmx. They only, as I found, fix this to manually edit edmx to remove links to the breaking association.

0
Dec 04 '13 at 20:26
source share

All you have to do is delete all your tables from the edmx file. Now right-click in the edmx file and select the update form database option. Update Ef, the problem will be solved.

0
Apr 04 '16 at 13:53 on
source share

I am using the first approach to the database and faced the same problem.

what was causing the problem of my colleague, deleted one of the tables from the database and forgot to update the model.

My solution finds the deleted object in the diagram. (The model browser may be useful.) Then remove it from the chart, since EF does not delete entities if you deleted the table from the database.

Build and check the error list window (Ctrl + E, W).

Done.

0
Nov 18 '16 at 20:58
source share

I also found that restoring your project after changes in the Entity Framework context, and models can sometimes resolve these errors, especially if the Entity Framework contexts are in another project.

0
Jan 25 '17 at 22:25
source share



All Articles