I have a Member entity with a complex type called Address with a complex type called UsState which has the following properties: Id, Name and Iso.
I need to map the Member Address’s UsState to its DB table column. The problem is that members table only contains State (VARCHAR) column, so in order to perform the right mapping, I did this:
modelBuilder.Entity<Member>().Property(p => p.BillingAddress.State.Name).HasColumnName("State");
modelBuilder.Entity<Member>().Ignore(p => p.BillingAddress.State.Id);
modelBuilder.Entity<Member>().Ignore(p => p.BillingAddress.State.Iso);
But it appears that Ignore only accepts base property lambdas, so I received this:
The expression 'p => p.BillingAddress.State.IsoCode' is not a valid property expression. The expression should represent a property: C#: 't => t.MyProperty' VB.Net: 'Function(t) t.MyProperty'.
How can I resolve this issue? (preferably using Ignore method)
Create a sublcass of
UsStateThen change the type of the
Stateproperty inBillingAddress‘s type toUsStateSpecific.Now ignore all desired properties from complex type (or entity)
UsStateSpecific. This will not affect your otherUsStateproperties in other types.