我正在使用Entity Framework 5(使用Code First方法)从带有参数的遗留存储过程填充我的一类,这很正常(详情如下).我的问题是我想将列的名称映射到具有不同名称的属性(我不喜欢来自Erp的名称).我尝试使用Configuration类(就像我映射到视图或表时所做的那样)来为具有不同名称的属性指定列名,这是我的结果:
为什么配置会影响我的结果,但其规范不用于映射列?有没有其他方法使用SqlQuery指定此映射?
以下是详细信息:
我的POCO课程:
public class Item
{
public String Id { get; set; }
public String Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
配置类:
public class ItemConfiguration : EntityTypeConfiguration<Item>
{
public ItemConfiguration()
{
HasKey(x => new { x.Id });
Property(x => x.Id).HasColumnName("Code");
Property(x => x.Description).HasColumnName("ItemDescription");
}
}
Run Code Online (Sandbox Code Playgroud)
存储过程返回带有"Code"和"ItemDescription"列的数据; 我用这种方式称呼它:
var par = new SqlParameter();
par.ParameterName = "@my_par";
par.Direction = ParameterDirection.Input;
par.SqlDbType = SqlDbType.VarChar;
par.Size = 20;
par.Value = ...;
var data = _context.Database.SqlQuery<Item>("exec …Run Code Online (Sandbox Code Playgroud) mapping configuration stored-procedures ef-code-first entity-framework-5