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 Query
- 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
More Query from same tag
- IndexOutOfRangeException was unhandled by user code
- LINQ to Entity RIA Query syntax?
- Entity Framework - Include Take Top N for each parent
- Check if an IEnumerable has less than a certain number of items without causing any unnecessary evaluation?
- Multiple Joins in Entity Framework query
- Azure Table Storage query by rowkey with leading zero
- Using linq how do i remove multiple records from a cross reference table
- Timeout issue with PostgreSQL and Entity Framework
- Dynamic linq filter children using pivot
- An error while doing a join linq query
- Select Distinct List of Words from Array with LINQ
- Is Access to Modified Closure warnings valid for string variable?
- how to cast object of type '<TakeIterator>[System.Data.DataView]' to type 'System.Data.DataView'.?
- Cast List<object> to List<myclass> c#
- Linq SQL Search - From tags with more matches
- LINQ query is slow
- Difficulty understanding particular lambda expression
- XML & Lambda - accessing fields that don't implement the IEnumerable interface
- How can an object-oriented programmer get his/her head around database-driven programming?
- Get custom linq lambda for sorting
- Linq expression equivalent of TSQL query
- Why am I getting such odd results from a GroupJoin?
- Find how many children you have of a certain type?
- linq query getting Unable to cast object of type 'System.Boolean' to type 'System.String'
- What's better for creating distinct data structures: HashSet or Linq's Distinct()?
- Why does this LINQ query fail to work?
- Using C# Linq find and return a string value from a multi-level data store
- How to include any enum value in property with Linq where clause
- Dynamically compose select using Linq to sql (EF6)
- how to get values from linked table using grouping key