poco - Entity Framework 4 Code First and the new() Operator -


I have a deep hierarchy of objects that I would like to do with unit framework 4, POCO, PI (continuity ignorance) It started when I had confidence in not using the new () operator. Originally in written form, objects often use new () to create child objects.

Instead, I am using myself on the repository pattern to make all the child objects as necessary. For example, given:

  class Adam {list & lt; Child & gt; children; Zero AddChildGivenInput (string input) {children.Add (new kid (...)); }} Category Children {List & lt; Grand Chald & gt; Grandsons; Zero AddGrandChildGivenInput (string input) {grandchildren.Add (New GrandChild (...)); <}           P> 
  Class AdamRepository {ADD ADD} {return objectContext.Create & lt; Adam & gt; (); } AddChildGivenInput (Adam Adam, string input) {return adam.children.Add (new child (...)); } GrandChild AddGrandchildGivenInput (child child, string input) {return child.grandchildren.Add (new GrandChild (...)); }}  

Now, it works well enough though, now I am not "ignorant" of my firmness system because I have left the new operator.

In addition to this, I have to face the risk, since there is a lot of logic in the repository, instead of domain objects.

After a lot of reaction, a question: / strong>

or many questions ...

  • Is it necessary to work with code 4?
  • Is there any way to maintain the use of new () and still work with EF 4 / Poko / Code first?
  • Is there any other pattern that can leave the argument in the domain object and still works with EF4 / POCO / code first?
  • Will this restriction be raised in the later versions of the code first support?

Sometimes the POCO / persistence ignorance tries to go the way seems like swimming upwards, at times it seems like Niagara Falls floats. Still, I want to believe ...

Here are some points that might help answer your question:

In your classrooms you have an area for the collection of children and there is a way to add children, usually EF (not just the code before) is currently necessary that the collection is in the form of the surface, therefore This pattern is currently not supported. How do we interact with classes? This is a general inquiry for more flexibility EF and our team is thinking about how we can support it at this time

You have mentioned that You need to clearly register the institutions with reference, it is not necessary that in the following example, if GetAdam () is connected to the underlying context of the Adam object, then the new child can Will be automatically detected by EF when you insert and save the database.

var adam = myAdamRepository << p>

adam.Children.Add (cain);

~ Rowan

/ div>

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -