当我执行以下语句时,我正在努力理解为什么查询会重新调整此错误:
SelectFor(x => x.Id == id, true, false, "Scope.Hiring.Scopes")
Run Code Online (Sandbox Code Playgroud)
上述语句中的字符串是要包含的实体。
SelectFor 方法:
public virtual TEntity SelectFor(Expression<Func<TEntity, bool>> predicate, bool noTracking = true, bool selectInactiveItems = false, params string[] entitiesToLoad)
{
var query = this.LoadRelatedEntities(this.transaction.Context.Set<TEntity>().AsQueryable(), entitiesToLoad);
query = query.Where(x => x.OwnerId == ownerId).Where(predicate);
if (!selectInactiveItems)
{
query = query.Where(x => x.Active);
}
if (noTracking)
{
query = query.AsNoTracking();
}
return query.FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)
包含方法
protected IQueryable<TEntity> LoadRelatedEntities(IQueryable<TEntity> query, params string[] entitiesToLoad)
{
if (entitiesToLoad != null && entitiesToLoad.Count() > 0)
{
foreach …Run Code Online (Sandbox Code Playgroud) 我想调用这个方法:
public IEnumerable<TEntity> SelectAll(params string[] entitiesToLoad)
Run Code Online (Sandbox Code Playgroud)
但是在大多数情况下我不会加载关系实体,所以我想调用它而不发送entitiesToLoad值,如下所示:
var dbResult = methodInfo.Invoke(repository, null);
Run Code Online (Sandbox Code Playgroud)
但它抛出异常,因为参数的数量不相等
有没有办法在不将params string []更改为其他类型的参数的情况下执行此操作?
我试过string entitiesToLoad = null as parammeter,我得到了同样的错误.