簡體   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