Dan*_*sco 13 mapping configuration stored-procedures ef-code-first entity-framework-5
我正在使用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 spItem @my_par", par);
Run Code Online (Sandbox Code Playgroud)
并且我将配置添加到上下文中:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ItemConfiguration());
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
Dan*_*sco 11
我在这里找到:
http://entityframework.codeplex.com/workitem/233?PendingVoteId=233
"SqlQuery方法的设计不考虑任何映射......".
他们还说"我们同意选择使SqlQuery荣誉列属性是有用的,所以我们将这个问题保持打开状态并将其放在我们的待办事项上以供将来考虑.",所以,如果你有同样的问题,请投票:-)
归档时间: |
|
查看次数: |
10903 次 |
最近记录: |