Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EntityFramework通用存储库,多个包含?_C#_Asp.net_Linq - Fatal编程技术网

C# EntityFramework通用存储库,多个包含?

C# EntityFramework通用存储库,多个包含?,c#,asp.net,linq,C#,Asp.net,Linq,我正在尝试从我的泛型存储库更改我的泛型检索方法。但是我想为includeProperty传递一个字符串,传递这个:params Expression[]includeProperty=null 问题是当我调用此方法时: public virtual IEnumerable<TEntity> Retrieve(Expression<Func<TEntity, bool>> filter = null, params Expression<Func<T

我正在尝试从我的泛型存储库更改我的泛型检索方法。但是我想为includeProperty传递一个字符串,传递这个:
params Expression[]includeProperty=null
问题是当我调用此方法时:

public virtual IEnumerable<TEntity> Retrieve(Expression<Func<TEntity, bool>> filter = null, params Expression<Func<TEntity, object>>[] includeProperties = null)

我做了一些类似的事情,但是使用表达式来急切地加载。也许这会有帮助:

    public TEntity Item(Expression<Func<TEntity, bool>> wherePredicate, params Expression<Func<TEntity, object>>[] includeProperties)
    {
        foreach (var property in includeProperties)
        {
            _dbSet.Include(property);
        }
        return _dbSet.Where(wherePredicate).FirstOrDefault();
    }
public tenty项(表达式wherePredicate,参数表达式[]includeProperties)
{
foreach(includeProperties中的var属性)
{
_数据库集。包括(财产);
}
返回_dbSet.Where(wherePredicate).FirstOrDefault();
}

你所做的是一种可怕的行为!我会告诉你很多。你正在打开你的API供包括你在内的所有人滥用。
includeProperties
是以字符串形式键入的,但你正在尝试向其发送lambda表达式。是的,我知道我必须更改字符串类型以及在查询中包含它们的方式…但我想进行编译包含..如果你知道我的意思。DarthVader API已打开互联网我只是想把它改成我的便利…@DarthVader我很好奇你会怎么打各种电话来获取数据,有时包括相关实体还是不包括?您是为每个排列添加方法还是对实体调用Load方法?我不是说你错了,我只是好奇。你可以把Where放在那里,然后直接使用。FirstOrDefault(wherePredicate);是的,自从这个答案最初发布以来的2.5年里,我也发现这是真的。
    public TEntity Item(Expression<Func<TEntity, bool>> wherePredicate, params Expression<Func<TEntity, object>>[] includeProperties)
    {
        foreach (var property in includeProperties)
        {
            _dbSet.Include(property);
        }
        return _dbSet.Where(wherePredicate).FirstOrDefault();
    }