代码之家  ›  专栏  ›  技术社区  ›  strager

Linq to SQL产生错误的SQL?

  •  0
  • strager  · 技术社区  · 14 年前

    我正在尝试运行Linq to SQL查询,但在计算查询时,出现以下异常:

    System.Data.OleDb.OleDbException was unhandled
      Message=The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
      Source=Microsoft JET Database Engine
      ErrorCode=-2147217900
      StackTrace:
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
           at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
           at System.Data.OleDb.OleDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
           at System.Data.Common.DbCommand.ExecuteReader()
           at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
           at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
           at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
           at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
           at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
           at xxx.InventoryPopulator`2.Clear(String barcode) in F:\Projects\C#\xxx\xxx\InventoryPopulator.cs:line 38
           [..etc..]
      InnerException: 
    

    调试器显示我的查询是:

    SELECT [t0].[SupplierID] AS [Id], [t0].[SupplierSKU] AS [Sku], [t0].[LocalSKU] AS [LocalSku], [t0].[ManufacturersBarcode] AS [Barcode], [t0].[QuantityAvailable]
    FROM [inventorySupplier] AS [t0]
    WHERE [t0].[ManufacturersBarcode] = @p0
    

    生成上述内容的Linq查询是:

    var items = from item in this.supplierItems
                where item.Barcode == barcode
                select item;
    

    如何修复查询?

    1 回复  |  直到 14 年前
        1
  •  1
  •   SLaks    14 年前

    要对其他数据库使用LINQ,您需要一个LINQ提供程序,例如 this one .