bltoolkit icon indicating copy to clipboard operation
bltoolkit copied to clipboard

BLToolkit Union and arrays

Open al-mar opened this issue 12 years ago • 3 comments

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));

al-mar avatar Jan 15 '13 15:01 al-mar

Try

var query = db.MyEntity.Select(s => s.Id).AsEnumerable().Union(new[] { 5 });

igor-tkachev avatar Jan 16 '13 23:01 igor-tkachev

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.

al-mar avatar Jan 17 '13 07:01 al-mar

Then I do not quite understand the problem.

igor-tkachev avatar Jan 23 '13 21:01 igor-tkachev