2015-05-11 13 views

Odpowiedz

1

The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities Jeśli jesteś gotów zmienić zapytanie trochę, to będzie działać:

var data = (from x in model.MyTable 
      where SqlFunctions.CharIndex(new byte[] { 1 }, x.BinaryColumn) == 1 
      select x).FirstOrDefault(); 

Zobacz MSDN

+0

, który zwróci wartość '1', a nie' 0 ', ponieważ SQL liczy od 1 – xanatos

+0

@xanatos, Naprawiono. Dzięki. – haim770

3

W TSQL funkcja SUBSTRING może być stosowany na binary/varbinary.

Gdzieś określić:

[DbFunction("SqlServer", "SUBSTRING")] 
public static byte[] SubString(byte[] field, int start, int length) 
{ 
    throw new NotSupportedException("Direct calls are not supported."); 
} 

następnie

var data = (from x in model.MyTable 
      where Substring(x.BinaryColumn, 1, 1) == new byte[] { 1 } 
      select x).FirstOrDefault(); 
Powiązane problemy