之前的分页接口都是正常的,突然就报错了Error parsing column 0 (Id=
{
"error": {
"code": null,
"message": "Error parsing column 0 (Id=)",
"details": "DataException: Error parsing column 0 (Id=)\r\nSTACK TRACE: at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in /_/Dapper/SqlMapper.cs:line 3706\r\n at Deserialize38f40c2b-6cb7-408c-8e8a-4c264ff79615(IDataReader)\r\n at Dapper.SqlMapper.GridReader.ReadBufferedAsync[T](Int32 index, Func`2 deserializer)\r\n at Dapper.SqlMapper.GridReader.ReadBufferedAsync[T](Int32 index, Func`2 deserializer)\r\n at Tzkj.Superhard.Talent.Query.TalentServiceDapperRepositoryBase.GetPagedResultAsync[T](String tablesJoinStr, String columnsStr, String whereStr, String orderByStr, Int32 pageIndex, Int32 pageSize, DynamicParameters queryParams)\r\n at Tzkj.Superhard.Talent.Query.ExpertAdvices.ExpertAdviceDapperRepository.GetPagedResultAsyncAdmin(String keyword, String create_time, Int32 pageIndex, Int32 pageSize)\r\n at Tzkj.Superhard.Talent.ExpertAdvices.ExpertAdviceAppService.GetPagedResultAsyncAdmin(GetExpertAdviceListInput getExpertAdviceListInput)\r\n at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()\r\n at Volo.Abp.GlobalFeatures.GlobalFeatureInterceptor.InterceptAsync(IAbpMethodInvocation invocation)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)\r\n at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()\r\n at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)\r\n at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()\r\n at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, AbpAuditingOptions options, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope)\r\n at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)\r\n at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()\r\n at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)\r\n at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)\r\n at Tzkj.Superhard.Talent.ExpertAdvices.ExpertAdviceController.GetPagedResultAsyncAdmin(GetExpertAdviceListInput getTalentPoolListInput)\r\n at lambda_method1332(Closure, Object)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\nFormatException: Could not parse CHAR(36) value as Guid: 3\r\nSTACK TRACE: at MySqlConnector.Core.TextRow.GetValueCore(ReadOnlySpan`1 data, ColumnDefinitionPayload columnDefinition) in /_/src/MySqlConnector/Core/TextRow.cs:line 57\r\n at MySqlConnector.Core.Row.GetValue(Int32 ordinal) in /_/src/MySqlConnector/Core/Row.cs:line 38\r\n at MySqlConnector.Core.Row.get_Item(Int32 ordinal) in /_/src/MySqlConnector/Core/Row.cs:line 392\r\n at MySqlConnector.MySqlDataReader.get_Item(Int32 ordinal) in /_/src/MySqlConnector/MySqlDataReader.cs:line 191\r\n at Deserialize38f40c2b-6cb7-408c-8e8a-4c264ff79615(IDataReader)\r\n",
"data": {},
"validationErrors": null
}
}
分页查询代码如下,执行到这里报错的 var list = await reader.ReadAsync
///
///
///
///
///
///
///
///
///
///
///
///
///
protected async Task> GetPagedResultAsync(
string tablesJoinStr,
string columnsStr,
string whereStr,
string orderByStr,
int pageIndex,
int pageSize,
DynamicParameters queryParams = null)
{
if (pageIndex <= 0 || pageSize <= 0)
{
//throw new ArgumentException("pageIndex与pageSize 不可以小于或等于0");
throw new UserFriendlyException("pageIndex与pageSize 不可以小于或等于0");
}
var skip = (pageIndex - 1) * pageSize;
var sb = new StringBuilder();
sb.AppendFormat("SELECT COUNT(1) FROM {0} where {1};", tablesJoinStr, whereStr);
sb.AppendFormat(@"SELECT {0}
FROM {1}
WHERE {2}
ORDER BY {3}
LIMIT @skip,@take", columnsStr, tablesJoinStr, whereStr, orderByStr);
queryParams ??= new DynamicParameters();
queryParams.Add("skip", skip, DbType.Int32);
queryParams.Add("take", pageSize, DbType.Int32);
var connection = await GetDbConnectionAsync();
var dbTransaction = await GetDbTransactionAsync();
using var reader = await connection.QueryMultipleAsync(sb.ToString(), queryParams, transaction: dbTransaction);
//using var reader = await connection.QueryMultipleAsync(sb.ToString(), queryParams);
var total = await reader.ReadFirstAsync();
var list = await reader.ReadAsync();//这里报错了
return new PagedResultQto(total, list.ToList());
}
查看返回的报错信息是id字段那报错了,网上说是代码里定义的模型跟数据库表里的类型不一致导致的,我看了下不是这个原因,最后查看查询出来的数据如下:id是1和2两列,那就不对了,代码里定义的是guid类型的,查询出来应该是36位的字符串才能正常转换成guid,所以报错了
综上,是数据库中的异常数据导致的