使用原生sql执行两个语句时,报错,报错内容为app_ext_col_0 返回
string query = "select isnull(AVG(CONVERT(DECIMAL(18,2),score)),0) AS aggregaterating,count(id) as reviewcount, isnull(SUM(CASE WHEN score=1 THEN 1 ELSE 0 END),0) AS Score_1, isnull(SUM(CASE WHEN score=2 THEN 1 ELSE 0 END),0) AS Score_2, isnull(SUM(CASE WHEN score=3 THEN 1 ELSE 0 END),0) AS Score_3, isnull(SUM(CASE WHEN score=4 THEN 1 ELSE 0 END),0) AS Score_4, isnull(SUM(CASE WHEN score=5 THEN 1 ELSE 0 END),0) AS Score_5 from tb_productreview where userid=@userid AND productid=@productid and showstate=1;SELECT id,reviewpic,haspic,hasvideo FROM dbo.tb_productreview(nolock) WHERE productid =@productid and userid =@userid AND (haspic = 1 OR hasvideo =1)"; SugarParameter[] parameters = new[] { new SugarParameter("@productid", productId), new SugarParameter("@userid", userId) }; Tuple<List<ProductReviewStatisticsModel>, List<TB_PRODUCTREVIEW>> list = await DbScoped.SugarScope.GetConnectionScopeWithAttr<TB_PRODUCTREVIEW>().Ado.SqlQueryAsync<ProductReviewStatisticsModel, TB_PRODUCTREVIEW>(query, parameters);
这个会报错,信息为
System.IndexOutOfRangeException: app_ext_col_0
at Microsoft.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
at Microsoft.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at SqlSugar.DbBindAccessory.SetAppendColumns(IDataReader dataReader)
at SqlSugar.DbBindAccessory.GetEntityListAsync[T](SqlSugarProvider context, IDataReader dataReader)
at SqlSugar.AdoProvider.GetDataAsync[TResult](Type entityType, IDataReader dataReader)
at SqlSugar.AdoProvider.SqlQueryAsync[T,T2,T3,T4,T5,T6,T7](String sql, Object parameters)
at SqlSugar.AdoProvider.SqlQueryAsync[T,T2](String sql, Object parameters)
at A.MongoService.Repository.ProductRepository.GetReviewStatistics(Int32 userId, Int32 productId)
at A.MongoService.MongoProductsService.GetProductById(Int32 ProductId, Int32 UserId)
at A.MongoService.MongoProductsService.Update(Int32 Id, Int32 siteId, MONGODBTASK task)
然后我测试在这句前面执行
var data = await DbScoped.SugarScope.GetConnectionScopeWithAttr< TB_PRODUCTREVIEW>().Queryable<TB_PRODUCTREVIEW>().With(SqlWith.NoLock).Where(x => 1 == 0).ToListAsync();
就不会报错了,这是为什么
热忱回答(2)
-
fate sta VIP01个月前
你是不是手动改数据库结构了
0 回复 -
fate sta VIP01个月前
或者2个库相同表但是结构不一样
0 回复