Is there any way to provide custom factory for .Net Framework creation Entities from EF4 ?

Posted by ILICH on Stack Overflow See other posts from Stack Overflow or by ILICH
Published on 2010-05-11T01:54:45Z Indexed on 2010/05/11 2:14 UTC
Read the original article Hit count: 252

There are a lot of posts about how cool POCO objects are and how Entity Framework 4 supports them. I decided to try it out with domain driven development oriented architecture and finished with domain entities that has dependencies from services. So far so good. Imagine my Products are POCO objects. When i query for objects like this:

NorthwindContext db = new NorthwindContext();
var products = db.Products.ToList();

EF creates instances of products for me.

Now I want to inject dependencies in my POCO objects (products) The only way I see is make some method within NorthwindContext that makes something like pseudo-code below:

public List<Product> GetProducts(){
    var products = database.Products.ToList();
    container.BuildUp(products); //inject dependencies
    return products;
}

But what if i want to make my repository to be more flexible like this:

public ObjectSet<Product> GetProducts() { ... }

So, I really need a factory to make it more lazy and linq friendly. Please help !

© Stack Overflow or respective owner

Related posts about entity-framework-4

Related posts about POCO