C# 实体检索方法应检索取消属性等于false的实体

C# 实体检索方法应检索取消属性等于false的实体,c#,properties,repository,C#,Properties,Repository,所有实体都派生自BaseEntity,该BaseEntity具有类型为bool的取消属性。我正在修改repository类中的GetList方法,该方法使用 public static IList<T> GetList<T>(Expression<Func<T, bool>> predicate) where T : BaseEntity 将返回已取消属性设置为false的实体列表,但如果实体的属性也是从BaseEntity派生的实体或从Base

所有实体都派生自BaseEntity,该BaseEntity具有类型为bool的取消属性。我正在修改repository类中的GetList方法,该方法使用

public static IList<T> GetList<T>(Expression<Func<T, bool>> predicate) where T : BaseEntity
将返回已取消属性设置为false的实体列表,但如果实体的属性也是从BaseEntity派生的实体或从BaseEntity派生的实体数组,如何将where子句添加到搜索查询中,以指定它还应仅检索取消属性设置为false的实体

范例

public class BaseEntity
{
    public bool Cancelled { get; set; }
    public int Id { get; set; }
}

public class Entity1 : BaseEntity
{
    public string Name { get; set; }
    public Entity3 Child { get; set; }
}

public class Entity2 : BaseEntity
{
    public string Name { get; set; }
    public IList<Entity3> Children { get; set; }
}

public class Entity3 : BaseEntity
{
    public string Name { get; set; }
}

但是我怎样才能把它添加到查询中呢?

我被你的问题弄糊涂了。您应该能够对父类的属性进行linq查询,而不会出现问题。这对您不起作用吗?是的,我可以使用query,但如果我想让developer不再手动指定e.Cancelled==false,并在GetListNonCancelled方法中自动执行该操作,该怎么办?
public class BaseEntity
{
    public bool Cancelled { get; set; }
    public int Id { get; set; }
}

public class Entity1 : BaseEntity
{
    public string Name { get; set; }
    public Entity3 Child { get; set; }
}

public class Entity2 : BaseEntity
{
    public string Name { get; set; }
    public IList<Entity3> Children { get; set; }
}

public class Entity3 : BaseEntity
{
    public string Name { get; set; }
}
if (property.PropertyType.BaseType == typeof(BaseEntity))