繁体   English   中英

为什么EF6不支持`忽略`实体Property(复杂属性)Fluent API的属性?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM