我有一个旧数据库,它有两个列,我想将它们映射为 1 个 ID,这可能吗
例如
public class Product
{
public string ProductID {get;set;}
public string ShortDescription {get;set;}
public string UserName {get;set;}
}
然后我的 Modelbinder 看起来像这样
modelBinder.Entity<Product>().
HasKey(p=>p.ProductID)
.MapSingle(product =>
new {
colShotDesc = product.ShortDescription,
colUser = product.UserName
}
).ToTable("Products");
我需要的是映射中的 ProductID = ShortDescription + UserName ...因为这两个列共享一个唯一的键约束...
不知道这是否有意义,但任何建议都会很棒......请不要询问数据库设计=>这就像它一样,不应该改变......这就是为什么我认为 EF 代码优先可以帮助我(希望交叉手指)......因为看起来数据库没有定义 pk 只是唯一的键约束......
无论如何...帮助会很棒..