C# 为什么EF6不支持“忽略”实体属性(复杂属性)Fluent API的属性?

C# 为什么EF6不支持“忽略”实体属性(复杂属性)Fluent API的属性?,c#,entity-framework,ef-fluent-api,C#,Entity Framework,Ef Fluent Api,如果实体为 public class AddressDetail { public string Country{get;set;} } public class Order { public AddressDetail AddressDetail{get;set;} } 如何通过Fluent API忽略或der.AddressDetail.Country属性而不是[NotMap] 我找到了EF6的解决方案,但我不知道为什么在EF6有这个功能之前,EF6没有这个功能 对于EF

如果实体为

public class AddressDetail 
{
   public string Country{get;set;}
}

public class Order
{
    public AddressDetail AddressDetail{get;set;}
}
如何通过Fluent API忽略
或der.AddressDetail.Country
属性而不是
[NotMap]

我找到了EF6的解决方案,但我不知道为什么在EF6有这个功能之前,EF6没有这个功能

对于EF5及以上版本:
DbContext.OnModelCreating
覆盖上下文中:

modelBuilder.Entity().Ignore(p=>p.AddressDetails.Country);
对于EF6:你运气不好。看


我理解这种例外情况,即只允许使用普通属性表达式,因此如果要忽略属性的属性,则必须对外部属性的类型执行此操作:

modelBuilder.Types<WhateverTheTypeOfResponseIs>()
    .Configure(c => c.Ignore(r => r.MobilePhone));
modelBuilder.Types()
.Configure(c=>c.Ignore(r=>r.MobilePhone));
不过,我想EF6的正确语法应该是:

modelBuilder.Entity<WhateverTheTypeOfResponseIs>()
    .Ignore(r => r.MobilePhone);
modelBuilder.Entity()
.忽略(r=>r.MobilePhone);

您是否尝试在属性上放置
[NotMapped]
属性?请参阅和@I想知道
[NotMapped]
为什么能够忽略该属性。
modelBuilder.Entity<WhateverTheTypeOfResponseIs>()
    .Ignore(r => r.MobilePhone);