0

我有以下属性声明和映射(精简类):

public class Consumer: AuditableEntity
{
    public virtual Consumer Parent { get; set; }
    public virtual User User { get; set; }
    public virtual Role Role { get; set; }
    public virtual ICollection<Consumer> Consumers { get; set; }
}

public ConsumerMap()
{
    HasRequired(t => t.Role)
        .WithMany(t => t.Consumers)
        .Map(a => a.MapKey("RoleId"))
        .WillCascadeOnDelete(false);
    HasRequired(t => t.User)
        .WithOptional(t => t.Consumer)
        .Map(a => a.MapKey("UserId"))
        .WillCascadeOnDelete(false);
}

手动数据库查询确认所有连接都成功,事实上,手动执行 EF 发送的查询是成功的。然而,当我使用以下查询时,返回User的两个Consumer对象的属性为空:

return CurrentDbContext.Consumers.Include("User").Include("Role").Where(e => !e.IsDeleted);
4

0 回答 0