I have a class Product
and a complex type AddressDetails
public class Product { public Guid Id { get; set; } public AddressDetails AddressDetails { get; set; } } public class AddressDetails { public string City { get; set; } public string Country { get; set; } // other properties }
Is it possible to prevent mapping "Country" property from AddressDetails
inside Product
class? (because i will never need it for Product
class)
Something like this
Property(p => p.AddressDetails.Country).Ignore();
In Entity Framework Core, the ModelBuilder class acts as a Fluent API. By using it, we can configure many different things, as it provides more configuration options than data annotation attributes.
Configuring a primary key By convention, a property named Id or <type name>Id will be configured as the primary key of an entity. Owned entity types use different rules to define keys. You can configure a single property to be the primary key of an entity as follows: Data Annotations.
Default Schema You can use the HasDefaultSchema method on DbModelBuilder to specify the database schema to use for all tables, stored procedures, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With