Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
No mapping specified for the following EntitySet/AssociationSet

Today I was working on a new project using Entity Framework 4. This is the first time I have used the model first approach available with EF 4 and came across an interesting compiler error, “No mapping specified for the following EntitySet/AssociationSet”. After that is listed several entities defined in my model. My first thought was it must be complaining about some of the associations I created between these entities. I had created many relationships just like I might designing my database tables first, so my thought was I had done something wrong.

So I searched for the error message using quotes. Side note: if you wrap your search term in quotes all the major search engines do a specific search for URLs containing that exact string. The only results I got back were relating to stored procedures, which I had none in my model. But I did find one secondary reference to an ASP.NET forum post on the error. The answer was not having the corresponding tables in my database yet. In other words I needed to Generate the Database from the Model.

So I did, which creates a SQL script, that must be executed. I am not sure why it wont just update the database for you, but I will deal with that later. I sort of can understand. So I executed the script, recompiled and viola the error has disappeared!

Posted: Sunday, March 28, 2010 12:23 PM

by Chris Love
Filed under:

Comments

John Bubriski said:

I haven't worked with 4.0 yet, but I think you get that error if there isn't a related table in the database. So basically, I think you need to map your entities to the actual data store? I'm pretty sure that 4.0 is supposed to be able to create the corresponding tables in the data store though... But again, I haven't actually used 4.0, so I'm what the process is for the model-first approach.
# March 29, 2010 10:52 AM

John Bubriski said:

In this video: http://channel9.msdn.com/posts/Eric+Nelson/Entity-Framework-4-Part-1-Simple-Model-First/ They right click on the designer area and click "Generate Database from Model". I think that is it!
# March 29, 2010 10:55 AM

Chris Love said:

John, that is what I said in the post :)

# March 30, 2010 10:00 AM

John Bubriski said:

Oops, my bad! For some reason, I thought you went and created the database yourself. Doh!
# March 30, 2010 10:43 AM

christianlouboutin said:

Very good article!
# July 12, 2010 10:00 PM

Deepak said:

Yes,.. I was struggling and this blog helped me out. after generating table it does not show error...cool
# August 5, 2010 12:35 PM

Matthew said:

What about starting with a "database first" project. I try to add a new entity and set a relation ship to an existing one and I get the same error. This database already has data in it. I cannot use the rather destructive rebuild script. Is there no way for it to currently just update the changes to the database? -- Matthew
# March 30, 2011 6:11 PM

Sascha said:

For a database first project you should define all relations within the database, so there will not appear any error
# April 6, 2012 5:26 AM

kag said:

That was really useful
# April 14, 2012 4:41 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS