很难确定此错误的根本原因,不确定是 devart 连接器问题还是什么。
我有两个查询,它们只是生成数据列表并在表中输出。当数据输出到表格中时,您可以对其进行分页。加载第一页(下面的第一个查询)成功。加载第二页会抛出异常(第二个查询)——异常如下所列。如果我使用 IQueryable ToQueryString ext 从系统中取出这些查询并在 mysql 中手动运行它们,它们都可以工作。我不知道接下来要测试/做什么。
两个查询之间的唯一区别是 LIMIT OFFSET 值。
这里是第一个在.net代码中成功并且直接作为MySql查询运行时成功的查询:
SELECT d0.City, d0.County, t.DiggerSearchId, t.DiggerSearchRequestId, t.DiggerSearchRequestJurisdictionId, d0.SearchType, d1.Debug, d2.ServiceCategory, d0.CourtType, d1.DOB, t.FailureCount AS FailCount, d1.FirstName, d1.LastName, d0.State, t.SentDateTime AS LastAttempt, d3.ActualResult, d3.ListResult, d3.ParserResult, d3.SearchResult
FROM (
SELECT d.DiggerSearchRequestJurisdictionId, d.DiggerSearchId, d.DiggerSearchRequestId, d.FailureCount, d.SentDateTime
FROM digger_work_queue AS d
WHERE d.Status = 0
LIMIT 10 OFFSET 0
) AS t
INNER JOIN digger_search AS d0 ON t.DiggerSearchId = d0.DiggerSearchId
INNER JOIN digger_search_requests AS d1 ON t.DiggerSearchRequestId = d1.DiggerSearchRequestId
LEFT JOIN digger_package AS d2 ON d1.DiggerPackageId = d2.DiggerPackageId
INNER JOIN digger_search_request_jurisdictions AS d3 ON t.DiggerSearchRequestJurisdictionId = d3.DiggerSearchRequestJurisdictionId
这是第二个查询,在 .net 代码中运行时失败,但在直接作为 MySql 查询运行时成功:
SELECT d0.City, d0.County, t.DiggerSearchId, t.DiggerSearchRequestId, t.DiggerSearchRequestJurisdictionId, d0.SearchType, d1.Debug, d2.ServiceCategory, d0.CourtType, d1.DOB, t.FailureCount AS FailCount, d1.FirstName, d1.LastName, d0.State, t.SentDateTime AS LastAttempt, d3.ActualResult, d3.ListResult, d3.ParserResult, d3.SearchResult
FROM (
SELECT d.DiggerSearchRequestJurisdictionId, d.DiggerSearchId, d.DiggerSearchRequestId, d.FailureCount, d.SentDateTime
FROM digger_work_queue AS d
WHERE d.Status = 0
LIMIT 10 OFFSET 10
) AS t
INNER JOIN digger_search AS d0 ON t.DiggerSearchId = d0.DiggerSearchId
INNER JOIN digger_search_requests AS d1 ON t.DiggerSearchRequestId = d1.DiggerSearchRequestId
LEFT JOIN digger_package AS d2 ON d1.DiggerPackageId = d2.DiggerPackageId
INNER JOIN digger_search_request_jurisdictions AS d3 ON t.DiggerSearchRequestJurisdictionId = d3.DiggerSearchRequestJurisdictionId
这里是查询在.net代码中执行时出现的异常:
Devart.Data.MySql.MySqlException: '你的 SQL 有错误 句法;查看与您的 MySQL 服务器版本对应的手册 对于在 ':10 附近使用的正确语法) AS t INNER JOIN digger_search AS d0 ON t.DiggerSearchId = d0.DiggerSearc' at line 6'
我不确定这是否与连接器在执行之前如何交换查询本身中的变量有关或与什么有关。
这是我们的 ToPagedList 扩展方法:
public static async Task<PagedList<T>> ToPagedListAsync<T>(this IQueryable<T> query, int pageNumber = 1, int totalRowsPerPage = 10) where T : class
{
// Initialize a new instance of PagedList<T>
var result = new PagedList<T>
{
// If pageNumber is not equal to 0, set CurrentPage to pageNumber; otherwise, set it to 1.
CurrentPage = pageNumber != 0 ? pageNumber : 1,
// If totalRowsPerPage is not equal to 0, set TotalRowsPerPage to totalRowsPerPage;
// otherwise, set it to 10.
TotalRowsPerPage = totalRowsPerPage != 0 ? totalRowsPerPage : 10,
// Set TotalRows to the count of items in the query.
TotalRows = query.Count()
};
// If totalRowsPerPage is not equal to -1 (indicating no paging), calculate paging
// information and retrieve the items for the current page.
if (totalRowsPerPage != -1)
{
// Calculate the total number of pages.
var totalPages = (double)result.TotalRows / result.TotalRowsPerPage;
result.TotalPages = (int)Math.Ceiling(totalPages);
// Calculate the number of items to skip and retrieve the items for the current page.
var skip = (result.CurrentPage - 1) * result.TotalRowsPerPage;
result.Items = await query.Skip(skip).Take(result.TotalRowsPerPage).ToListAsync();
}
else
{
// If totalRowsPerPage is -1, retrieve all items in the query.
result.Items = await query.ToListAsync();
}
// Return the paged list.
return result;
}
我将连接器从 Devart 切换到官方 MySql 连接器,查询现在可以正常工作了。我相信这可能是 Devart MySql 连接器的错误。
修复 EF Core 7 中生成参数以双冒号为前缀的 bug。这是 下载链接,用于使用修复程序内部构建的 NuGet 包。