[英]Why EF6 not support ` ignore ` the property of the entity Property(complex property) Fluent API?
如果实体为
public class AddressDetail
{
public string Country{get;set;}
}
public class Order
{
public AddressDetail AddressDetail{get;set;}
}
如何通过Fluent API Not [NotMap]
忽略Oreder.AddressDetail.Country
属性?
我找到了EF6的解决方案,但是我不知道为什么在EF6拥有功能之前,EF6没有功能?
对于EF5和更旧版本:在
DbContext.OnModelCreating
覆盖上下文中:
modelBuilder.Entity<Product>().Ignore(p => p.AddressDetails.Country);
对于EF6:您不走运。 参见Mrchief的回答 。
我理解这个例外,即仅允许使用普通属性表达式,因此,如果要忽略属性的属性,则必须在外部属性的类型上执行此操作:
modelBuilder.Types<WhateverTheTypeOfResponseIs>()
.Configure(c => c.Ignore(r => r.MobilePhone));
虽然,我猜EF6的正确语法是:
modelBuilder.Entity<WhateverTheTypeOfResponseIs>()
.Ignore(r => r.MobilePhone);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.