bltoolkit
bltoolkit copied to clipboard
BLToolkit Union and arrays
The following query doesn't work:
var query = db.MyEntity.Select(s => s.Id).Union(new[] { 5 });
It seems like unions accept only queries as their parameters, because the query below works fine:
var query = db.MyEntity.Select(s => s.Id).Union(db.MyEntity.Select(s => s.Id));
Try
var query = db.MyEntity.Select(s => s.Id).AsEnumerable().Union(new[] { 5 });
That's not a query to database. And it can't be used in other queries as a subquery. The "new[] { 1, 2, 3, 4, 5 }" expression in union could be rewrited as "db.MyEntity.Select(s => s.Id).Where(s => new[] { 1, 2, 3, 4, 5 }.Contains(s))" in some cases (if MyEntity table really contains such ids). But "new[] { 1, 2, 3, 4, 5 }" is more convenient and less complicated.
Then I do not quite understand the problem.