I have the following setup, abridged for brevity:
public abstract class AuditableEntity
{
public int Id { get; set; }
public Login Login { get; set; } // Login that create this identity.
}
public class Login: AuditableEntity
{
public Security Security { get; set; }
public Guid SessionGuid { get; set; }
}
public class Security: AuditableEntity
{
public string UserName { get; set; }
public string PasswordHash { get; set; }
}
如今,在<代码><<<0> /代码>上不要求实体本身填写。 事实上,它不属于该表,因此,我忽略了:
modelBuilder.Entity<Login>().Ignore(l => l.Login);
我想,正如所有其他表格所要求的那样,但当我如在<代码>上尝试和要求时。 用户:
modelBuilder.Entity<Security.Security>().Property(p => p.Login).IsRequired();
我收到一个汇编错误,即“为了将其用作参数T, Log必须是不可损失的价值类型”。 我注意到,我获准在前面的<代码>Ignore中将其用作参数T,因此,我认为这是其他一些隐蔽的T。
My immediately apparent solutions are not very elegant:
- Use an FK value and not a reference poperty for
Login
in inAuditableEntity
. - Create a new base class without
Login
, and another derived from that that addsLogin
, then inherit my Login class from the highest base, and all other classes from its immediate descendant.
是否有更好的办法这样做?