Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to SQL: View to Table Association not generating code

I have a dmbl with a bunch of tables and some views where I set up an Association in the Designer from the View to the Table. Then in code I try and write some code that "uses" that association and it isn't there. I look in the designer file and I don't see anything in there either.

Strange thing is I have done this before successfully with these same tables and views in a different dbml and project. All that changed was we moved everything from a 2005 SQL Server to a 2008R2 Box.

like image 332
Refracted Paladin Avatar asked Aug 18 '12 19:08

Refracted Paladin


2 Answers

Linq2SQL does this if your 'view' does not have a primary key. So add a pseudo one L2S can use. :)

like image 199
leppie Avatar answered Oct 18 '22 23:10

leppie


Views can be added to the design and manual associations can be added between them and other tables/views. However, the association will not create a parent/child property in the code unless you modify the view properties to define "primary keys".

https://conficient.wordpress.com/2008/06/04/linq-to-sql-faq-associations-to-views/

like image 26
Dasith Wijes Avatar answered Oct 18 '22 22:10

Dasith Wijes