0
通用对象我有一个问题,以通用对象复制到通用对象通用对象与Automapper
public class Customer
{
public int CustomerId { get; set; }
public virtual ICollection<Quote> Quotes { get; set; }
}
我用这个通用类,复制对象对象:
public static class GenericAutomapper
{
public static void PropertyMap<T, U>(T source, U destination)
where T : class, new()
where U : class, new()
{
Mapper.CreateMap(typeof(T), typeof(U));
Mapper.Map<T, U>(source); //crash here
}
}
当我得到一个客户(使用EF 6.1.2)并且使用这个方法,我在“crash here”这一行发生错误。行情收集的样子: “((System.Data.Entity.DynamicProxies.Customer_AC635AD71AC95634EF9694FDC434135B488FD116F3C2B6A287846A7886521F3F)源).Quotes”
我没有任何问题,当我有这样的:.Include(x => x.Quotes)
我的查询中,正常的集合被加载。
有没有办法管理“未加载”集合?
感谢,
这个班级必须保持通用,当然没有关于班级的具体内容。 – 2014-12-02 08:29:02
映射类将保持特定的,但问题是,你试图映射动态代理类,这不是一个好主意。你需要执行这个查询(它不会是通用的,因为我期望你将在特定的DBSet上工作),然后调用AutoMapper映射函数。这会给你具体的类型,并允许地图起作用。这是提供有限信息的最佳猜测。 – WestDiscGolf 2014-12-02 08:47:13