Linq to SQL; Missing Related 'Child' Objects

by Andrew Barber 31. August 2011 01:32

Just a quick note about something that happens to me now and again when using Linq to SQL, and takes a moment to realize what's going on.

Say you are coding using Linq to SQL, in ASP.NET MVC, for example. You notice, either via intellisense or failed compilation, that a related, child object collection does not exist, even though it's in your database, the relation is set properly, and you have the entities created in the designer. So, what gives?

When this happens to me, I find that I've forgotten to designate the child table's primary key field as a primary key (and identity field) properly. Fix this, re-generate the entities, and problem solved!

Comments are closed

Links/Profile

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent those of my partners, clients or contractors in any way.

© Copyright 2012 AndrewBarber.com