0
プロパティと異なるタイプの1つのテーブルにマップできる複数のプロパティを持つクラスがあります。 これは、各プロパティに対して同じスキーマを持つ複数のテーブルを持たないようにしました。 としては、次のとおりです。次のようにEF複数のプロパティを同じテーブルにマッピングします。関係がタイプ ''が利用できないのでロードされませんでした
public class ExtraInfoBase
{
public int Id { get; set; }
public InfoType Type { get; set; }
public string Value { get; set; }
public string Extra { get; set; }
public virtual Flower Flower { get; set; }
public virtual User User { get; set; }
}
マッピング:
public class FlowerMap : EntityTypeConfiguration<Flower>
{
public FlowerMap()
{
this.HasKey(t => t.Id);
this.ToTable("Flowers");
this.Property(t => t.Id)
.HasColumnName("Id")
.HasColumnType("uniqueidentifier");
this.Property(t => t.Type)
.IsRequired()
.HasColumnName("Type");
this.HasRequired(t => t.Family).WithRequiredPrincipal(x => x.Flower);
this.HasRequired(t => t.Gender).WithRequiredPrincipal(x => x.Flower);
this.HasRequired(t => t.Specie).WithRequiredPrincipal(x => x.Flower);`
public class ExtraInfoBaseMap : EntityTypeConfiguration<ExtraInfoBase>
{
public ExtraInfoBaseMap()
{
this.HasKey(t => t.Id);
this.ToTable("ExtraInfo");
this.Property(t => t.Id)
.HasColumnName("Id")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(t => t.Type)
.IsRequired()
.HasColumnName("Type");
this.Property(t => t.Value)
.IsRequired()
.HasColumnName("Value");
this.Property(t => t.Extra)
.HasColumnName("Extra");
this.HasRequired(x => x.Flower);
this.HasRequired(x => x.User);
}
}
私は取得しています
public class Flower : Entity
{
public Flower()
{
Events = new Collection<Event>();
}
public Guid Id { get; set; }
public virtual User User { get; set; }
public FlowerType Type { get; set; }
public virtual ExtraInfoBase Family { get; set; }
public virtual ExtraInfoBase Specie { get; set; }
public virtual ExtraInfoBase Seller { get; set; }
public string SellerObs { get; set; }
public virtual ExtraInfoBase Localization { get; set; }
Extrainfobaseがdiferentタイプを持つすべてのこれらのプロパティを扱うことができるクラスです。エラータイプ 'ExtraInfoBase'が利用できないため、 'Flower_Family'という関係はロードされませんでした。 何が間違っていますか? お知らせください。
'ExtraInfoBase'が' Entity'を継承していれば動作しますか? – mjwills
あなたの投稿に 'User'クラスも含めてください。 – mjwills