orm - Best Way to convert one Edmx Entity to one Business entity -
i developing 1 application in data access edmx entities , have fill each business entity after retriving data edmx entity like:-
var tblproducts = tblproductsdata .select(t => new tblproduct() { categoryid = t.categoryid, description = t.description, id = t.id, image = t.image, insdt = t.insdt, price = t.price, quantity = t.quantity, status = t.status, title = t.title, tblcategory = new efdbfirst.models.tblcategory() { id = t.tblcategory.id, status = t.tblstatus.statusid, title_category = t.tblcategory.title_category }, tblstatu = new efdbfirst.models.tblstatu() { statusdescription = t.tblstatus.statusdescription , statusid = t.tblstatus.statusid } });
i fadeup because everytime have convert 1 while getting data , setting data in db, there way create common mehod takes 1 anonymous type , converts anonymous type.
thanks in advance
your example isn't clear.
first of all, ef doesn't work anonymous types inside itself, works ef types have defined either using edmx file or code first. can create anonymous types defining select statement.
e.g:
var products = context.tblproductsdata .select(r => new { description = r.description }); //new without typename //anonymous object
the tblproduct, tblcategory , tblstatu objects, ef types? if so, don't need write select, ef generate objects when execute it.
e.g:
var products = context.tblproductsdata.tolist();
this automatically generate tblproduct objects you. when try navigate tblproduct.tblcategory or tblproduct.tblstatu, lazy loading retrieve them you. if want explicit load them during first query (eager-loading) use include
function.
e.g:
var products = context.tblproductsdata.include(r => r.tblcategory) .include(r => r.tblstatu).tolist();
however if tblproducts, tblcategory , tblstatu business objects , not ef types, there isn't other way this, have explicit create them in select statement.
Comments
Post a Comment