小编Rap*_*iro的帖子

'角色名称为X的RelatedEnd已经加载

当我执行以下语句时,我正在努力理解为什么查询会重新调整此错误:

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)

c# entity-framework-6

3
推荐指数
1
解决办法
1308
查看次数

如何调用params string []作为唯一没有发送值的参数的方法

我想调用这个方法:

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,我得到了同样的错误.

c# system.reflection

2
推荐指数
1
解决办法
243
查看次数

标签 统计

c# ×2

entity-framework-6 ×1

system.reflection ×1