От: | Angler | ||
Дата: | 29.12.10 12:20 | ||
Оценка: |
IEnumerable<Table> FindRecords(DataContext dc, IEnumerable<Key> keys);
class Key
{
public a1 {get;}
public a2 {get;}
public a3 {get;}
}
IEnumerable<Table> FindRecords(DataContext dc, IEnumerable<Key> keys)
{
var q = from t in dataContext.Table
from key in keys
where t.a1 == key.a1 && t.a2 == key.a2 && t.a3 == key.t3
select t;
return q;
}
An unhandled exception of type 'System.NotSupportedException' occurred in System.Data.Linq.dll
Additional information: Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator.
IEnumerable<Table> FindRecords(DataContext dc, IEnumerable<Key> keys)
{
var q = from t in dataContext.Table
from key in keys
where keys.Contains(makeKey(t.a1, t.a2, t.a3))
select t;
return q;
}
IEnumerable<Table> FindRecords(DataContext dc, IEnumerable<Key> keys)
{
return keys
.SelectMany(key => dataContext.Table.Where(t => t.a1 == key.a1 && t.a2 == key.a2 && t.a3 == key.t3));
}