Monday, June 7, 2010

LINQ to SQL Association issue

Recently I faced an issue while working with LINQ. In my Database there were two entities which are having many-many relationship. Then I created the relationship as below. [I have omitted other entities and some columns for simplicity.]
Then I map the Database to C# code using LINQ to SQL dbml file. After that I have realized above mentioned associations are missing in that file. I tried several things but not worked and finally googled on this matter. Fortunately there were people who faced the same issue. I went through following link,

http://www.eggheadcafe.com/software/aspnet/33898713/association-missing-in-db.aspx

and it gave me the answer.
Then what I did was,


(Created a Primary key to intermediate table.)

Then delete previous 3 tables and drag/drop the new tables to designer. That’s it, association was there.

No comments :