2

if the entity as

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

public class Order
{
    public AddressDetail AddressDetail{get;set;}
}

How ignore the Oreder.AddressDetail.Country property by Fluent API Not [NotMap]?

I found the solution for EF6,but I don't know Why Before EF6 have the function,EF6 don't have the function?

For EF5 and older: In the DbContext.OnModelCreating override for your context:

modelBuilder.Entity<Product>().Ignore(p => p.AddressDetails.Country);

For EF6: You're out of luck. See Mrchief's answer.

enter image description here

huoxudong125
  • 1,966
  • 2
  • 26
  • 42
  • Have you tried putting a `[NotMapped]` attribute on the property? – Knelis Jan 14 '16 at 09:14
  • 2
    See http://stackoverflow.com/questions/24400719/ignore-some-inherited-properties-in-ef6-code-first-mapping-net4-not-net4-5 and http://stackoverflow.com/questions/21839131/telling-ef-6-to-ignore-a-private-property – Paul Zahra Jan 14 '16 at 09:22
  • @I want to know why`.[NotMapped]` is able to ignore the property. – huoxudong125 Jan 14 '16 at 09:57

1 Answers1

0

I understand this exception that only plain property expressions are allowed, so if you want to ignore the property of a property, you have to do it on the type of the outer property:

modelBuilder.Types<WhateverTheTypeOfResponseIs>()
    .Configure(c => c.Ignore(r => r.MobilePhone));

Though, i guess the proper syntax for EF6 would be:

modelBuilder.Entity<WhateverTheTypeOfResponseIs>()
    .Ignore(r => r.MobilePhone);
C. Sura
  • 98
  • 6