score:3
Accepted answer
Try:
public Func<DataContext, int, IQueryable<Item>> Query1 =
CompiledQuery.Compile((DataContext context, int id) =>
(from table1 in context.GetTable<Table1>()
where table1.foreignId = id
select new Item(table1))
.Union(
(from table2 in context.GetTable<Table2>()
where table2.foreignId = id
select new Item(table2))
));
Source: stackoverflow.com
Related Articles
- using union on linq compiled queries
- How to combine two linq queries using Union
- Simplify the following code to a one-liner using Linq queries
- Convert string[] to int[] in one line of code using LINQ
- Remove duplicates while merging lists using Union in LINQ
- Is it possible to accelerate (dynamic) LINQ queries using GPU?
- If it's bad to use inline SQL, how does using LINQ to perform queries differ in practice?
- Union A List of Lists Using Linq
- Using expressions in the "Select" part of LINQ to entities queries
- How to Union two Queries in LINQ to Fluent NHibernate?
- LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Good way to time SQL queries when using Linq to SQL
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- LINQ Source Code Available
- Should I be using LINQ queries on RavenDB?
- Linq Compiled Query using Contains (Like SQLs IN statement)
- How to write LINQ Queries for CRUD using Entity Framework?
- Are LINQ to Entites 4.0 Queries Compiled By Default?
- Using Compiled Linq To SQL with ExecuteMethodCall
- EF: Is there way to force Linq using UNION instead of UNION ALL
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- how do i build dynamic linq queries at runtime using strings?
- using let keyword in linq to combine queries
- Linq compiled queries without passing the context
- Using linq to query SQL Server is causing 100s of small queries
- C# .Net 3.5 Code to replace a file extension using LINQ
- Saving the result of a linq query to an XML file
- System.Data.Linq.Mapping Modify class marked as [Table]
- Use LINQ to get length of dimensions of Array
- Stack depth of PSeq threads (or of those used by System.Linq.ParallelEnumerable)
- LInq Order By and Order By Desc
- How can I omit NULL values when converting DataRow to a Dictionary in C#?
- LINQ Query problem. Need to check if exists
- Using LINQ To Find Total Number of Objects in C#
- Left excluding join using LINQ in vb.net
- Setting visiblilty of control using LINQ
- Creating objects from xml error {"Value cannot be null.\r\nParameter name: element"}
- How to call an Sql User defined Function using Entity frame work Code first approach with LInq c#
- What is the difference between LINQ ToDictionary and ToLookup
- Issue with custom EqualityComparer
- NHibernate 3.0: No FirstOrDefault() with QueryOver?
- LINQ approach to this code
- LINQ - Left Join, Group By, Sum,
- Linq, Left Join and Dates
- Sort dictionary by value - descending THEN alphabetical C#
- Updating RadGridView after Editing Records in Real Time