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