LINQ To SQL requires Primary Key!
March 6, 2008After 8 months of playing with LINQ I have only JUST found out that LINQ To SQL *Requires* a primary key on every table. This includes many to many mapping tables!
I only found this out by accident after forgetting to mark my ID column as PK. I guess this means that my good practice of putting a Primary key on every table is a good one! =]
hi.
how to requires Primary Key?
by css November 9, 2008 at 2:02 pmThe primary key value will be in that property after the SubmitChanges()??
but my code didn’t work
by css November 9, 2008 at 2:04 pmHi CSS,
Yes you need to call SubmitChanges for the primary key property to get populated. If you want, email me your code and I can take a look.
by robert112s2k November 11, 2008 at 10:14 amhi.
robert112s2k.
thanks you. it is done.
===========================
old code
===========================
db.SubCategoryValueRelation.InsertOnSubmit(subCategoryValueRelation.ToDataAccess());
db.SubmitChanges();
return subCategoryValueRelation.SCVRID;
=================================
by css December 10, 2008 at 6:33 amnew code
================================= DataAccess.SubCategoryValueRelation s =
subCategoryValueRelation.ToDataAccess();
db.SubCategoryValueRelation.InsertOnSubmit(s);
db.SubmitChanges();
return s.SCVRID;