Linq-to-SQL会产生错误的SQL?

时间:2010-06-08 13:39:55

标签: linq-to-sql

我正在尝试运行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 个答案:

答案 0 :(得分:1)

LINQ to SQL只能与SQL Server一起使用。

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