0

我有一些课

public class Class1
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public Guid Class1Id { get; set; }
    public List<MediaSet> MediaSet { get; set; }
}

public class Class2
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public Guid Class2Id { get; set; }
    public List<MediaSet> MediaSet { get; set; }
}

public class MediaSet
{
    [Key]
    public int MediaSetId { get; set; }
    public Guid ObjectId { get; set; }
    public List<Media> Media { get; set; }
}

public enum MediaType { Photo, Video }

public class Media
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public Guid MediaId { get; set; }
    public MediaType MediaType { get; set; }
    public string Url { get; set; }
    public int MediaSetId { get; set; }
    [ForeignKey("MediaSetId")]
    public MediaSet MediaSet { get; set; }
}

我想通过单个属性属性 ObjectId 将类 MediaSet 映射到 Class1 和 Class2,我该怎么做?这样以后我就可以执行以下查询

var classes1WithMediaSet = MyDbContext.Classes1.Include(x => x.MediaSet).ToList();
var classes2WithMediaSet = MyDbContext.Classes2.Include(x => x.MediaSet).ToList();
4

0 回答 0