I've got rather complicated real-life scenario of EF Mapping, which seems to work only if I break incapsulation. Maybe someone would clear it out how to do it correctly, or we'll accept it is a bug.
I have 2 projects, let's call them Domain and Persistance. Domain contains POCO classes, and exposes it's internals to Persistance by the InternalsVisibleTo attribute.
Inside the Domain (the aim is to persist the SomeProduct):
pubic class Company { ... }
pubic class InsuranceCompany : Company { ... }
pubic class Product<TCompany> where TCompany : Company
{
...
public CustomValueType SomeProp { ...
// get/set from/into SomePropInternal
}
internal string SomePropInternal { get;set; }
// exposed as internal to be accessible from EF mappings
}
public class SomeProduct : Product<InsuranceCompany>
{
...
public AnotherCustomValueType AnotherSomeProp { ...
// get/set from/into AnotherSomePropInternal
}
internal string AnotherSomePropInternal { get;set; }
// exposed as internal to be accessible from EF mappings
}
I need to end with one table SomeProduct with all the fields. So, in the Persistance we have:
Inside the Persistance:
Base configuration type for all Products:
public class ProductEntityTypeConfiguration<TProduct, TCompany> : EntityTypeConfiguration<TProduct>
where TProduct : Product<TCompany>
where TCompany : Organization
{
public ProductEntityTypeConfiguration()
{
...
Property(_ => _.SomePropInternal)
.IsRequired()
.IsUnicode()
.HasMaxLength(100);
}
}
And for SomeProduct:
public class SomeProductMap : ProductEntityTypeConfiguration<SomeProduct, InsuranceCompany>
{
public SomeProductMap()
{
ToTable("Business.SomeProduct");
Property(_ => _.AnotherSomePropInternal)
.IsRequired()
.IsUnicode()
.HasMaxLength(100);
}
}
When I try to Add-Migration with these mappings, it says that SomePropInternal is not declared on the type SomeProduct.
If I change the internal string SomePropInternal to public string SomePropInternal migration gets created. It's the problem. I do not want to expose that must-be-private property.
For AnotherSomePropInternal everything works fine with internal.