当 POCO 有字典时,将抛出转换错误。查询中未包含的列表和其他标量属性将使用其默认值初始化(列表正确初始化为 null)但字典不是
错误:
附加信息:无法将类型“Simple.Data.SimpleRecord”隐式转换为客户。示例:假设我的 POCO 看起来像这样..
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IDictionary<AddressType, Address> Addresses { get; set; }
public string FullName
{
get
{
return string.Concat(LastName, ", ", FirstName);
}
}
public Customer()
{
this.Addresses = new Dictionary<AddressType, Address>();
}
}
然后在我的 DAL 中我有这样的东西...... _db 是动态的 Simple.Data 数据库对象。
假设我的 Customer 表只有以下列:id、firstname 和 lastname。
public IEnumerable<Customer> GetCustomers()
{
return _db.dbo.Customer.All()
.ToList<Customer>();
}
有没有人遇到过这个问题?任何解决方法?