DotNetNext / SqlSugar

.Net aot ORM Fastest ORM Simple Easy VB.NET Sqlite orm Oracle ORM Mysql Orm 虚谷数据库 postgresql ORm SqlServer oRm 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm Object/Relational Mapping

Home Page:https://www.donet5.com/Home/Doc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

导航查询,把填充子对象封装到自己的仓储里面会报错。

wbflike opened this issue · comments

commented

仓储封装代码

 public virtual async Task<List<TEntity>> GetIncListAsync(Expression<Func<TEntity, bool>> expression, params Expression<Func<TEntity, object>>[] propertySelectors)
        {
            //创建一个实体查询对象
            var query = _db.Queryable<TEntity>();
            //添加导航查询
            if (propertySelectors != null && propertySelectors.Length > 0)
            {
                foreach (var propertySelector in propertySelectors)
                {
                    query.Includes(propertySelector);
                }
            }
            return await query.Where(expression).ToListAsync();
        }

调用代码

 var res = await _baseRepository.GetIncListAsync(m => m.Id == 6083572115833349, m => m.Role);

报错代码

System.Reflection.TargetException: Object does not match target type.
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.PropertyInfo.GetValue(Object obj)
   at SqlSugar.NavigatManager`1.<>c__DisplayClass62_0.<OneToOne>b__6(Object n)
   at System.Linq.Lookup`2.CreateForJoin(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.JoinIterator[TOuter,TInner,TKey,TResult](IEnumerable`1 outer, IEnumerable`1 inner, Func`2 outerKeySelector, Func`2 innerKeySelector, Func`3 resultSelector, IEqualityComparer`1 comparer)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SqlSugar.NavigatManager`1.OneToOne(List`1 list, Func`2 selector, EntityInfo listItemEntity, PropertyInfo navObjectNamePropety, EntityColumnInfo navObjectNameColumnInfo)
   at SqlSugar.NavigatManager`1.ExecuteByLay(Expression expression, List`1 list, Func`2 selector)
   at SqlSugar.NavigatManager`1.ExecuteByLay(Int32 i, Expression item)
   at SqlSugar.NavigatManager`1.Execute()
   at SqlSugar.QueryableProvider`1._InitNavigat[TResult](List`1 result)
   at SqlSugar.QueryableProvider`1.<>c__DisplayClass145_0`1.<_InitNavigatAsync>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at SqlSugar.QueryableProvider`1._InitNavigatAsync[TResult](List`1 result)
   at SqlSugar.QueryableProvider`1._ToListAsync[TResult]()
   at WebApplication1.Entitys.BaseRepository`1.GetIncListAsync(Expression`1 expression, Expression`1[] propertySelectors) in E:\Git\WebApplication1\Entitys\BaseRepository.cs:line 161
   at WebApplication1.Controllers.HomeController.Get() in E:\Git\WebApplication1\Controllers\HomeController.cs:line 24
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

KR98EJAEK_H@6_57_OBFQ}P

更新最新预览版本用我封装好的,你封装可能有难度

直接加载第二所有导航对象 ,第三第四层需要手动处理

ISugarQueryable IncludesAllFirstLayer(params string[] ignoreProperyNameList); 不想加载的可以忽略

如果还有疑问,发布新的isssue这个先关闭