Map complex CSLA BO to Entity Framework with eager loading

Map complex CSLA BO to Entity Framework with eager loading

Old forum URL: forums.lhotka.net/forums/t/10759.aspx


BGrojer posted on Monday, October 10, 2011

Hi,

MyObjectFactory calls a EntityFramework (EF) DAL and load a Entity with several childs. The ObjectFactory maps the result to a CSLA BusinessObject.
The child entities are already loaded with a .Include(...) in the same EF query and there is no need to call the database again. How should no map the child-entites to child CSLA child business objects?
Should I define another ObjectFactory for the childs and define a GetChildList method that takes a EF Object List as a argument to avoid another call to the database?

Thanks,
Bernhard

JonnyBee replied on Tuesday, October 11, 2011

My personal preference is to map BO and ObjectFactory 1:1.

So I would create a

 

BGrojer replied on Tuesday, October 11, 2011

Thank you for your feedback.

Does this mean u recommend this:

public class MainBOObjectFactory
{
public MainBO Fetch(int id)
{
 var query = from c in ctx.Products.Include("Orders") select c;
var result = query.First();
 var childs = new ChildBOObjectFactory().FetchList(result.Orders);

LoadProperty(... properties ...);
LoadProperty(... childList ...);
}
}

public class ChildBOObjectFactory
{
public ChildBOList FetchList(IEnumerable<Order> orders)
{
 //for each: map an order to a childBo
//return ChildBoList
}
}

Copyright (c) Marimer LLC