我有一个旧数据库,其中有两列数据,我想将它们映射为1个ID,这是否可行?
例如:
public class Product
{
public string ProductID {get;set;}
public string ShortDescription {get;set;}
public string UserName {get;set;}
}
那么我的模型绑定器应该长这样:
modelBinder.Entity<Product>().
HasKey(p=>p.ProductID)
.MapSingle(product =>
new {
colShotDesc = product.ShortDescription,
colUser = product.UserName
}
).ToTable("Products");
我需要的是类似于ProductID = ShortDescription + UserName的映射方式,因为这两个列共享一个唯一键约束...
不知道这是否有意义,但任何建议都会很好... 请不要询问数据库设计 => 它是现成的,不应更改...这就是为什么我认为EF代码优先可以帮助我(希望能成功)... 因为它看起来像数据库没有定义主键,只有唯一键约束...
无论如何...帮助将是非常棒的...