c# - Generic object to generic object with Automapper -
i have problem copy generic object generic object
public class customer { public int customerid { get; set; } public virtual icollection<quote> quotes { get; set; } }
i use generic class copy object object :
public static class genericautomapper { public static void propertymap<t, u>(t source, u destination) t : class, new() u : class, new() { mapper.createmap(typeof(t), typeof(u)); mapper.map<t, u>(source); //crash here } }
when customer (using ef 6.1.2) , use method, on error on "crash here" line. quotes collection : '((system.data.entity.dynamicproxies.customer_ac635ad71ac95634ef9694fdc434135b488fd116f3c2b6a287846a7886521f3f)source).quotes'
i don't have problem when include : .include(x => x.quotes)
in query, normal collection loaded.
is there way manage "not loaded" collection ?
thanks,
you need either turn off lazy loading or execute query before mapping; call .include() helps or need .tolist() (or similar) before applying mapping.
Comments
Post a Comment