question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How express `SELECT1 UNION ALL SELECT 2` sub-query in Linq2Db

See original GitHub issue

I have a query which uses IN clause:

var query = dataContext.ExecuteObject<Card>()
                .Where(x => x.Version == workingVersion);
                .Where(x => cities.Contains(x.CityId));

which is not very effective, because cities collection is quite big (and provided by user request). I would like to replace IN clause with INNER JOIN like that:

[x1].CityId IN (1, 2, 3, 4)
INNER JOIN (SELECT 1 AS Id UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) [c] ON [c].Id = [x1].[CityId]

How can I express such SELECT UNION in Linq2Db?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Nov 29, 2016

@NickAb, you can create temp table using linq2db, bulk copy data to that table and use inner join. It sholuld be more effective.

0reactions
ilicommented, Feb 22, 2017

Solution needed, or we can close an issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

union of different types using linq2db
select 'True' from DocumentField_1 where DocumentField_1.DocumentId = 2 union all select CONVERT(varchar, value) from DocumentField_2 where ...
Read more >
Joining two subqueries with union all and join leads to ...
CustomerID IN ( SELECT Id FROM @ids ) UNION ALL SELECT '0' ) -- Join t1 to the top half of the original...
Read more >
How to use"Union ALL" to join sql queries each containing ...
I have 2 sql statements and each sql statement is having orderby clause when i am use" UNION ALL " to join them...
Read more >
Writing Better Performing Queries with LINQ on EF Core 6.0 ⚙️
These two queries will translate to same SQL if you keep an eye out using SQL Server Profiler. SELECT [e].[Name] FROM [Employees] AS...
Read more >
Subqueries - Azure Cosmos DB for NoSQL
Subqueries in Azure Cosmos DB for NoSQL · SELECT VALUE COUNT(1) FROM products p JOIN t in p. · SELECT VALUE COUNT(1) FROM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found