0
停止反復にはほとんど反映されていない流暢なAPIを使用するにはどうすればよいですか?反射型でEF Fluent APIを使用するにはどうすればいいですか
サンプルコード;
public abstract class Entity : IEntity
{
public int Id { get; set; }
}
public class SemiStructuredEntity : Entity
{
public virtual int DocumentId { get; set; }
[ForeignKey("DocumentId")]
public virtual Document Document { get; set; }
}
public class Payment : SemiStructuredEntity
{
public string Code { get; set; }
}
public class Member : SemiStructuredEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Document : Entity
{
public string UniversalId { get; set; }
public string Subject { get; set; }
}
および流動性;
modelBuilder.Entity<Member>()
.HasRequired(a => a.Document)
.WithMany()
.HasForeignKey(u => u.DocumentId);
modelBuilder.Entity<Payment>()
.HasRequired(a => a.Document)
.WithMany()
.HasForeignKey(u => u.DocumentId);
SemiStructuredEntity基底クラスで継承された別のクラスが必要な場合は、別の流暢性を定義する必要があります。
私の夢は、
List<Type> targetTypes = getSemiStructuredEntities();
///
///and now How? How can i define fluent for all of targetTypes in second statements?
///
または
List<Type> targetTypes = getSemiStructuredEntities();
foreach (Type item in targetTypes)
{
///
///And now How? How can i define fluent for this type
///
}
事前に感謝を(私の質問は、コードブロック内の行をコメント)。