1

I'm new to Linq-SQL and have used the O/R designer to generate my data classes.

My main data table has a couple of 1:M (child-parent) relationships and these associations have been set up in the designer.

What I want to be able to do is something like:

Child c = new Child();
Parent p = new Parent();
p.Children.Add(c);

The Properties pane for the association contains the table name (pluralised) as the name of the child property, but the Parent class generated by the designer doesn't have a collection of Children (or even "Childs").

I've read elsewhere that it is best to let the designer get on with it (see e.g. the comments on this question), but the auto-generated code doesn't seem to give me what I need.

How can I tell the designer to create the necessary collection properties? Alternatively, how would I go about doing it by hand?

Community
  • 1
  • 1
Tom Wright
  • 11,278
  • 15
  • 74
  • 148

1 Answers1

0

Check out http://msdn.microsoft.com/en-us/data/jj713299
Try it with a small new project and do it step by step like on the MSDN website, then you may find the step you haven't done in your project. If "Navigation Property" is checked on both sides and you have checked "Add foreign key properties to the Entity" on both sides then you should be able to create your entity instances and add them to the belonging entity instance.

MarkusEgle
  • 2,795
  • 4
  • 41
  • 61
  • Thanks. I wasn't using EF before, but your suggestion prompted me to try it. It now works pretty much as expected and the new bugs are beyond the scope of this question! – Tom Wright Jan 24 '14 at 16:59