Не ответ.
Я изменил тест, чтобы ему было легче работать, и нашел более неправильный:
A И B AND ID = '00000000-0000-00000000-0000000000 '
B И A И (ID =' 0000000-0000-0000-0000-000000000000 ')
Мне это кажется ошибкой.Возможно, вы захотите передать его в Microsoft Connnect.
using System;
using System.Data;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable("dt")
{
Columns =
{
new DataColumn("ID", typeof(Guid)),
new DataColumn("A", typeof(bool)),
new DataColumn("B", typeof(bool)),
}
};
dt.Rows.Add(Guid.Empty, false, false);
dt.Rows.Add(Guid.Empty, false, true);
dt.Rows.Add(Guid.Empty, true, false);
dt.Rows.Add(Guid.Empty, true, true);
Console.BackgroundColor = ConsoleColor.Black;
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
foreach (DataRow row in dt.Rows)
Console.WriteLine("ID = {0}, A = {1}, B = {2}", row["ID"], row["A"], row["B"]);
Console.WriteLine();
// this incorrectly returns a row
Test(dt, "B AND A AND ID = '00000000-0000-0000-0000-000000000000'");
// these correctly return 0 rows
Test(dt, "B AND A");
Test(dt, "B AND A AND CONVERT(ID, 'System.String') = '00000000-0000-0000-0000-000000000000'");
Test(dt, "A AND B AND ID = '00000000-0000-0000-0000-000000000000'");
Test(dt, "B = 1 AND A AND ID = '00000000-0000-0000-0000-000000000000'");
Test(dt, "ID = '00000000-0000-0000-0000-000000000000' AND B AND A");
Test(dt, "B AND (A AND ID = '00000000-0000-0000-0000-000000000000')");
Test(dt, "(B AND A AND ID = '00000000-0000-0000-0000-000000000000')");
// still wrong
Test(dt, "B AND A AND ID = '00000000-0000-0000-0000-000000000000'");
// also incorrect for both A = True and B = True
Test(dt, "B AND A AND (ID = '0000000-0000-0000-0000-000000000000')");
if (Debugger.IsAttached)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine();
Console.WriteLine("Press any key to continue . . . ");
Console.ReadKey();
}
Console.ResetColor();
Console.Clear();
}
public static void Test(DataTable dt, string filter)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(filter);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(" DT = {0}, DV = {1}",
dt.Select(filter).Length,
new DataView { Table = dt, RowFilter = filter }.Count);
}
}