Arne Claassen

I just ingested a Schema using the a Linq to SQL DBML file in the designer. All looked good and seemed to be properly referenced. Then i tried to add a row to a lookup table like below:

Code Snippet



using (MyDataContext db = new MyDataContext(ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString))
{
track_status_enum x = new track_status_enum();
x.enum_value = TrackStatus.Archive.ToString();
x.track_status_id = (byte)TrackStatus.Archive;
feed_item_comment_track f = null;
db.track_status_enums.Add(x);
db.SubmitChanges();


This resulted in the following error on the Add() line:

Invalid association mapping for member 'Feedelity.DAL.track_status_enum.feed_item_comment_tracks'. 'Feedelity.DAL.feed_item_comment_track' is not an entity.

track_status_enum is a lookup referenced by a bunch of tables as a status field and feed_item_comment_track is one of them. Since i wasn't adding anything to those tables, I don't even know why it's interacting with them on this add, anyhow, but regardless, feed_item_comment_track is defined the same as track_status_enum, so i expect it to be an entity for linq.

Any suggestions what this error actually means and where to start troubleshooting

thanks
arne


Re: LINQ Project General Invalid association mapping error in Add()

Matt Warren - MSFT

It's likely that the lookup table is missing its primary key.




Re: LINQ Project General Invalid association mapping error in Add()

fmether

Turns out feed_item_comment_track was the one missing its PK. The lookup table was fine. Added the PK and all is good. Thanks!