asp.net mvc 3 - Entity Framework POCO Serialization -



asp.net mvc 3 - Entity Framework POCO Serialization -

i start code new web application soon. application built using asp.net mvc 3 , entity framework 4.1 (database first approach). instead of using default entityobject classes, create poco classes using ado.net poco entity generator.

when create pocos using tool, automatically adds virtual keyword properties alter tracking , navigation properties lazy loading.

i have read , seen demonstrations, julie lerman (ef guru!) seems turn off lazy loading , modifies poco template virtual keyword removed poco classes. julie states reason why because writing applications wcf services , using virtual keyword causes serialization issue. says, object getting serialized, serializer touching navigation properties triggers lazy loading, , before know pulling whole database across wire.

i think julie perhaps exagarating when said pull whole database across wire, however, so, thought scares me!

my question (finally), should remove virtual keyword poco classes mvc application , utilize dectectchanges alter tracking , eager loading request navigation properties.

your help appreciated.

thanks ever.

serialization can indeed trigger lazy loading because getter of navigation property doesn't have way observe if caller serializer or user code.

this not issue: whether have virtual navigation properties or properties virtual ef create proxy type @ runtime entities, hence entity instances serializer have deal @ runtime typically of type different 1 defined.

julie's recommendations simplest , reasonable way deal issues, if still want work capabilities of proxies of time , serialize them wcf, there other workarounds available:

you can utilize datacontractresolver map proxy types serialized original types you can turn off lazy loading when serialize graph

more details contained in blog post: http://blogs.msdn.com/b/adonet/archive/2010/01/05/poco-proxies-part-2-serializing-poco-proxies.aspx

besides this, recommendation utilize dbcontext template , not poco template. dbcontext new api released part of ef 4.1 goal of providing greater productivity. has several advantages fact automatically perform detectchanges won't need in general care calling method yourself. poco entities generate dbcontext simpler ones generate poco templates. should able find lots of mvc exampels using dbcontext.

asp.net-mvc-3 serialization entity-framework-4.1 lazy-loading poco

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -