Linq to entities insert problem – make sure the qualifiedEntitySetName is correct

After drinking cold coffee in agony for 24 hours over the Insert functionality in Linq to Entities, I finally stumbled up on a good solution.  I had been getting errors like ..  “The member with identity ‘Entities’ does not exist in the metadata collection. Parameter name: identity” in the Context.AddObject() method.
First of all I found the core place to be for my concerns and questions. The ADO.Net forum and then I found this post which really got me on the track.
Ended up solving all my problems with the following when inserting an object with 2 foreign keys;  Course and User which are of types (Course and User);  for which I don’t want to retrieve the objects from the database just to add them as the foreign keys for the insert.  The eventual solution for the insert looks like this (with the root problem bolded).
public void InsertRound(Round round)
{
round.UserReference.EntityKey = new EntityKey(DBContext.DefaultContainerName + “.User”, “Id”, round.IdUser);
round.CourseReference.EntityKey = new EntityKey(DBContext.DefaultContainerName + “.Course”, “Id”, round.IdCourse);
DB.AddToRound(round);
DB.SaveChanges();
}

3 thoughts on “Linq to entities insert problem – make sure the qualifiedEntitySetName is correct

  1. Undeniably imagine that which you said. Your favorite justification
    seemed to be on the internet the easiest thing to consider of.
    I say to you, I definitely get annoyed even as folks think about issues that they plainly
    don’t recognise about. You managed to hit the nail upon the top as neatly as outlined out the whole thing without having side effect , other people can take a signal. Will probably be again to get more. Thank you

  2. It’s remarkable to visit this web site and reading the views of all colleagues regarding this piece of writing, while I am also zealous of
    getting familiarity.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s