使用实体框架

时间:2018-06-08 19:03:52

标签: asp.net-mvc entity-framework-core

我在另一篇文章中提出了问题,但似乎这不是正确的问题,所以要在此重新提出:

我有三个班级:

public class StateLog : BaseModel
{
    public Guid StateLogId { get; set; }
    public Guid LookupMasterId { get; set; }


    public  Guid EntityId { get; set; }

    public string Discriminator { get; set; }

    public bool IsActive { get; set; }

    public virtual LookupMaster State { get; set; }
}

第二课:

public class ApplicationState : StateLog
{
   [Column("EntityId")]
   public  Guid ApplicationId { get; set; }
}

还有另一个继承自StateLog的Class DocumentStates。

应用:

public class Application : BaseModel
{
    public Guid ApplicationId { get; set; }        
    public Guid UserId { get; set; }
    public virtual User User { get; set; }
    [Required]
    public Guid ApplicationTypeId { get; set; }
    public bool? AuthorizedToWork { get; set; } = false;
    public string Token { get; set; }
    public string ApplicationTitle { get; set; }
    public string WorkStartDate { get; set; }
    public Nullable<DateTime> SignedAt { get; set; } = DateTime.Now;
    public bool? Signed { get; set; }
    public string Notes { get; set; }

    public virtual ICollection<ApplicationSelfDeclaration> ApplicationSelfDeclarations { get; set; }

    public virtual ICollection<ApplicationState> ApplicationStates { get; set; }

    public virtual ICollection<StateLog> StateLogs { get; set; }
}

我正在尝试在同一个表中保存应用程序和文档的状态日志,并基于Discriminator,获取数据。

E.g。

_context.Applications.include(a => a.ApplicationState)

这不起作用。 ApplicationState应将Alias EntityId列作为ApplicationId。但它没有用。

现在知道我的选择是什么吗?

提前致谢。

0 个答案:

没有答案