我有一个映射在datacontext中的表.这是感兴趣的列的属性和属性:
[Column(Storage="_CustomerNumber", DbType="VarChar(25)")] public string CustomerNumber {
实际上,该列是varchar(25)并具有索引.
我有一些简单的代码:
DataClasses1DataContext myDC = new DataClasses1DataContext(); myDC.Log = Console.Out; ListmyList = new List () { "111", "222", "333" }; myDC.Customers .Where(c => myList.Contains(c.CustomerNumber)) .ToList();
哪个生成此SQL文本:
SELECT [t0].[CustomerNumber], [t0].[CustomerName] FROM [dbo].[Customers] AS [t0] WHERE [t0].[CustomerNumber] IN (@p0, @p1, @p2) -- @p0: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [111] -- @p1: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [222] -- @p2: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [333] -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8
请注意,参数是nvarchar!
当此查询命中数据库时,它会生成一个可怕的计划,该计划涉及将CustomerNumber上的数百万行索引转换为nvarchar,然后再在其中进行搜索.
我不允许更改表,但我可以更改查询和dbml.如果不进行此索引转换,我该怎么做才能获取数据?