Entity Framework Code First will auto-create a table in the database base based on the Model.
Is there an attribute that will avoid this?
The Entity Framework Core Fluent API provides two Ignore methods. One belongs to the ModelBuilder class and is used to specify that the entity should not be mapped to a database table. The other Ignore method is available on the EntityTypeBuilder class and enables you to exclude individual properties from mapping.
The NotMapped attribute is used to specify that an entity or property is not to be mapped to a table or column in the database. In the following example, the AuditLog class will not be mapped to a table in the database: public class Contact. {
Add the [System.ComponentModel.DataAnnotations.Schema.NotMapped]
attribute to the property.
Per the accepted answer and similar question/answer, in addition to [NotMapped]
you can also specify it using the Fluent API:
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty); base.OnModelCreating(modelBuilder); }
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