How do I create two associated entities at one time with EF4 Code-First?

You can initialize the list in the client code itself: Post post = new Post { Text = "Blah" Poststory = new List() { new Poststory { Text = "Blah" } } }; context.Posts. Add(post); context.SaveChanges() However, there is nothing wrong with initializing the collection inside the constructor and it is actually recommended because it saves you from having to initialize it in all the client codes.

You can initialize the list in the client code itself: Post post = new Post { Text = "Blah" Poststory = new List() { new Poststory { Text = "Blah" } } }; context.Posts. Add(post); context.SaveChanges(); However, there is nothing wrong with initializing the collection inside the constructor and it is actually recommended because it saves you from having to initialize it in all the client codes.

Initializing the collection as a list works but it's not a good option. The reason is that you cant convert a List to an EntityCollection (so I can check if the collection has been eager loaded for example). – KallDrexx Feb 18 at 1:22 How do you check if the collection is eager loaded with EntityCollection?

– Morteza Manavi Feb 18 at 1:54 The EntityCollection class has an IsLoaded property – KallDrexx Feb 18 at 3:12 And that's only valid when you have entityobjects in place. When using POCOs, the last thing you want to do is to tightly coupled them to the EF which is a very well known anti-pattern. – Morteza Manavi Feb 18 at 3:43 I agree with not wanting them coupled with EF, I'm just trying to find a way to let the DB system create the ICollection, but it's looking less and less like that's possible – KallDrexx Feb 18 at 4:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions