Ignoring all implemented interface properties in EF CodeFirst

Not so long ago, I used the DataBase First approach with edmx models. I created partial classes to extend the functionality of domain models created by edmx.

//Generated by tt in edmx
public partial class DomainObject
{
    public int PropertyA {get; set;}
    public int PropertyB {get; set;}
}

//My own partial that extends functionality on generated one       
public partial class DomainObject: IDomainEntity
{
    public int EntityId {get; set;}
    public int EntityTypeId {get; set;}
    public int DoSomethingWithCurrentEntity()
    {
        //do some cool stuff
        return 0;
    }
}

All particles implemented the IDomainEntity interface

public interface IDomainEntity
{
    int EntityId {get; set;}
    int EntityTypeId {get; set;}
    int DoSomethingWithCurrentEntity();

    //Another huge amount of properties and functions
}

Thus, all the properties of this interface were not mapped to tables in the DataBase.

Now I move on to the Code First approach, and all these properties are trying to map to DataBase. Of course, I could use the [NotMapped] attribute, but the number of properties in the interface and classes is huge (over 300) and continues to grow further. Is there any approach to ignore all properties from a partial or interface for all classes at once.

+4
source share
1

, , , Fluent API DbContext.OnModelCreating:

foreach(var property in typeof(IDomainEntity).GetProperties())
    modelBuilder.Types().Configure(m => m.Ignore(property.Name));
+4

All Articles