【发布时间】:2020-11-23 01:22:12
【问题描述】:
我正在迁移到 EF Core 并尝试使用 2 个参数调用存储过程。
1 个参数的当前设置工作正常。
这是我看到的错误:
System.InvalidOperationException:FromSqlRaw 或 FromSqlInterpolated 是使用不可堆肥的 SQL 调用的,并且在其上进行了查询。考虑在 FromSqlRaw 或 FromSqlInterpolated 方法之后调用
AsEnumerable以在客户端执行组合。在
这是我的存储库调用:
public IQueryable<PartsGridDTO> GetPartsGridQueryable(int partId, int groupId)
{
return MoreContext.SpPartsGridDetailYourCases
.FromSqlRaw($"EXECUTE dbo.GetProductsByPartAndGroup {partId}, {groupId}")
.Select(s => new PartsGridDTO
{
PartId = partId,
//....
}).AsQueryable();
}
我从这里尝试了一些修复:
Include with FromSqlRaw and stored procedure in EF Core 3.1
但这些都不起作用。
我将返回AsQueryable() 直到控制器,然后调用.ToListAsync()。
我尝试在.AsQueryable() 之前添加.IgnoreQueryFilters();,但我仍然看到错误。
有什么想法吗?我是否传递了错误的参数?是 EF Core 问题还是?
【问题讨论】:
-
@JuanPablo:我试过这些,但它仍然给我同样的错误:-(
.FromSqlRaw($"GetProductsByPartAndGroup @p0, @p1", partId, groupId) -
@JuanPablo 和
.FromSqlRaw($"GetProductsByPartAndGroup @p0 @p1", partId, groupId)