カプセル化を解除した場合にのみ機能するように見える、EF マッピングの実際のシナリオはかなり複雑です。誰かがそれを正しく行う方法を明らかにするかもしれません。さもなければ、それはバグであると受け入れるでしょう。
私は 2 つのプロジェクトを持っていDomain
ますPersistance
。Domain
POCO クラスを含み、その内部を属性Persistance
によって公開します。InternalsVisibleTo
内部Domain
(目的はを永続化することです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
}
SomeProduct
すべてのフィールドを含む 1 つのテーブルで終了する必要があります。したがって、次のようになりPersistance
ます。
内部Persistance
:
すべての基本構成タイプProducts
:
public class ProductEntityTypeConfiguration<TProduct, TCompany> : EntityTypeConfiguration<TProduct>
where TProduct : Product<TCompany>
where TCompany : Organization
{
public ProductEntityTypeConfiguration()
{
...
Property(_ => _.SomePropInternal)
.IsRequired()
.IsUnicode()
.HasMaxLength(100);
}
}
SomeProduct の場合:
public class SomeProductMap : ProductEntityTypeConfiguration<SomeProduct, InsuranceCompany>
{
public SomeProductMap()
{
ToTable("Business.SomeProduct");
Property(_ => _.AnotherSomePropInternal)
.IsRequired()
.IsUnicode()
.HasMaxLength(100);
}
}
これらのマッピングで Add-Migration を実行しようとすると、SomePropInternal is not declared on the type SomeProduct
.
に変更するinternal string SomePropInternal
と、public string SomePropInternal
移行が作成されます。それが問題です。私はそのプライベートなプロパティを公開したくありません。
AnotherSomePropInternal
すべてが正常に動作しますinternal
。