0

I'm using EF 6.1, Database First. I have Lazy Loading disabled.

If I load an entity without Eager loading its Collection Navigation Properties, would I ever have to worry that these navigation properties were not properly initialized? Should I be able to use entity.collectionnavigationproperty.Add(new entity) without worrying about initializing the collection navigation property first?

Intensivist
  • 767
  • 2
  • 7
  • 19
  • Its a good idea to initialize you collections in the constructor of the model. Take a look at this post http://stackoverflow.com/q/5982254/673105 – DFord Nov 04 '14 at 06:11
  • Database First creates my model. If I modify the code it would get overwritten each time I update the model from the database. Doing this is not intuitive to me. The Collection Navigation Properties in my entities created with new() or loaded to memory have not been null and seem to work when I use .Add() to the collection property. I seem to be missing the point here. What situation should I be modifying my DF created POCOs to initialize (and with what) collection navigation properties? – Intensivist Nov 04 '14 at 11:14

1 Answers1

0

I'm not sure how it works for models created without DataBase First, but it seems that all my entities with Collection Navigation Properties are initialized in the constructor with HashSet<>. That's why I have not encountered issues with nulls or having .Add fail.

Intensivist
  • 767
  • 2
  • 7
  • 19