Entity framework 使用Context.Database.SqlQuery执行存储过程<;T>;和复杂类型映射
我有一个名为Product的类,其结构如下:Entity framework 使用Context.Database.SqlQuery执行存储过程<;T>;和复杂类型映射,entity-framework,stored-procedures,mapping,ef-code-first,complextype,Entity Framework,Stored Procedures,Mapping,Ef Code First,Complextype,我有一个名为Product的类,其结构如下: public class Product { public long Id { get; set; } public string Title { get; set; } public string Summary { get; set; } public string Description { get; set; } public long ProductCategoryId { get
public class Product
{
public long Id { get; set; }
public string Title { get; set; }
public string Summary { get; set; }
public string Description { get; set; }
public long ProductCategoryId { get; set; }
public virtual ProductCategory ProductCategory { get; set; }
public ConstantPost ConstantPost { get; set; }
}
有一种称为ConstantPost的复杂类型。
当我想执行一个名为mostbound的存储过程时,会出现以下错误:无法为类型为“Domain.ConstantPost”的属性“ConstantPost”创建值。仅支持具有基元类型的属性。 如何在执行存储过程时忽略复杂类型
提前感谢。目前不支持此操作。您不能从
SqlQuery
返回包含复杂类型的实体,谢谢。我想我应该创建另一个模型来检索我的数据。我简直不敢相信这是不受支持的。这似乎是一种相对常见的数据存储方式。存储、更新和删除数据与适当的ModelBuilder
信息完美配合,因此我不确定自己是否理解为什么使用完全相同格式的存储过程拉回数据会导致此错误。除了编写冗余模型之外,没有其他方法可以解决这个问题了?@Eric:尝试在DbSet
实例上使用SqlQuery
。@LadislavMrnka,你能详细说明一下吗?@LadislavMrnka,你能详细说明一下吗?直接在DbSet
实例上调用SqlQuery
会产生相同的错误。