In EF 6, I can add a NotMapped
attribute to the property, then it will not be mapped to a column. How can I do this in EF 7?
We haven't implemented data annotations yet. (See #107) You should be able to do it using the Fluent API.
modelBuilder.Entity<MyEntity>().Ignore(e => e.NotMappedProperty);
Just to add on to Ricky and bricelam's answer,
There are two ways to ignore a property:
Data annotations on model
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
[NotMapped]
public DateTime LoadedFromDatabase { get; set; }
}
Fluent API overriding OnModelCreating
class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.Ignore(b => b.LoadedFromDatabase);
}
}
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public DateTime LoadedFromDatabase { get; set; }
}
Documentation available here.
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