EFCore 7和Devart.Data.MySql.EFCore9.1.134.7奇怪的查询语法错误

svgewumm  于 2023-04-19  发布在  Mysql
关注(0)|答案(2)|浏览(112)

有一个非常困难的时间确定这个错误的根本原因,不确定是否是一个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 d 0 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;
}
rqqzpn5f

rqqzpn5f1#

我把连接器从Devart切换到官方的MySql连接器,查询现在可以工作了。我相信这可能是Devart MySql连接器的一个bug。

sdnqo3pr

sdnqo3pr2#

EF Core 7中生成参数前缀为双冒号的错误已修复。这里是修复后的NuGet包内部构建的download link

相关问题