score:2
you can use compiled query in other query but you can't make it dependent on the outer query. examples
// you can do
var someparams = 10;
var dataquery = from x in ctx.somedata
join y in mycompiledquery.invoke(ctx, someparams)
on x.id equals y.id
where x.name = "abc"
select new { x, y };
// you can't do - this example will not compile but let's use it for description
var dataquery = from x in ctx.somedata
join y in mycompiledquery.invoke(ctx, x.someparams)
on x.id equals y.id
where x.name = "abc"
select new { x, y };
the difference is that first example just executes delegate (compiled query is a delegate) and returns iqueryable
. the second example can't execute delegate because it is dependent on outer query data so it takes it as something that must be added to expression tree and eveluated during query execution. this fails because ef provider is not able to translate delegate invocation.
score:0
you can combine and embed queries, but i do not think you can use compiled queries. it really shouldn't matter much though, because ef will only compile the combined query once and then cache it (and the database backend should cache the associated query plan).
you could therefore use something along these lines:
var reviewquery = from mcq in reviews
select new
{
prod_id = mcq.prod_id
rating = mcq.review_rating,
review = mcq.review_text
};
from cat in ctx.cat_table
join prod in ctx.prod_table on cat.category_id equals prod.category_id
select new
{
cat_id = cat.category_id,
prod_id = prod.product_id,
name = prod.product_name,
descript = prod.product_description,
price = prod.price,
reviews = from r in reviewquery where r.prod_id == prod_id select r
}
Source: stackoverflow.com
Related Query
- Can I use a compiled query as a source in a second query?
- Can I Use The Same Linq Code to Query for Different Conditions?
- Can I cite a Compiled Query as the Data Source to a Compiled Query?
- How can I switch that code to use LINQ
- How can I write the following code more elegantly using LINQ query syntax?
- What Linq query can I use to return a count of all products by Category?
- Use a linq query as microsoft local report Data Source (WinForms)
- Can I use a query designer to write Linq Queries against a DataSet
- How can I code a Linq query to do an upward Include?
- How I Can use Linq Query count no. of record in query
- How can we express the following code using query expression?
- How can i change this LINQ query to use my List<int> instead of the hard coded number?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How can I use a predicate in a crm sdk 2011 linq query when the query contains a join?
- Can I use a LINQ IEnumerable result as the data source for a Gtk.TreeView?
- How can I code numerous MIN functions into one LINQ to DataSet query
- How can I use this T-SQL query in LINQ / Entity Framework?
- How can i use cross Tab Query in c# linq?
- How can I use custom expressions in DevArt LINQ to Entities and also use query comprehension syntax?
- How can I use this extension method in a linq to entities query using query syntax?
- How can I reformat this to use the other kind of LINQ Query format?
- How can I use Distinct operator in C# LINQ query
- How can I use query syntax from Linq for return random records?
- Linq query that can use a list of DateTime to filter a List<object>
- Can I use LINQ to query two Lists to populate a single List
- Can I assign the result of a Linq query to the source variable of the same query?
- How to assign LINQ Query to a variable and then use it later in the code
- How can I filter a simple LINQ query and use it in a more complexe LINQ query
- How can I use this Linq Query using it with a multiple parameter by Join tables
- Why can I not use the same poco in code first in EF4.1 to project my data?
More Query from same tag
- How to concatenate all child elements with same names values using LINQ to XML
- Updating List using LINQ working when execute from Immediate window, not from code direct
- Simplest way to perform grouping/projection using Linq To Objects
- NHiberate 3 linq paged query + total count 1 hit to the database
- How to do Guid.TryParse in Linq query
- Linq multiple where with sorted order
- MVC, Passing count of 3 tables to view
- Get Except of multiple nested dictionaries using LINQ expression
- Linq to Entities 4.0 ('Include'): In search of an elegant way
- Passing a string as a sortable parameter to use in a Linq query
- Changes to an IEnumerable are not being kept between queries
- How would I get the corresponding Key for the maximum Value in a Dictionary(Of SomeEnum, Integer) using LINQ?
- System.IO - Use Directory/LINQ to Replace Some Files in a List with Others
- Grouping / Multiple grouping with LINQ
- DataContext not visible when choosing data source for LinqDataSource
- replace value of element in XML
- how can this SQL be done in LINQ?
- why are there 2 different variables in this linq statement?
- Whats wrong with this LINQ query
- C# deserialize xml using linq
- How To Check If Two List Of Tuple's Item2 Have Similar Values?
- Using Linq in an Anon Type using one of the Anon Types Properties
- linq to entities if filter parameter is null then select all entities?
- How to create new columns from List<T> values?
- The cast to value type 'Int32' failed
- Using LINQ Distinct in C#
- How to compare decimal DBNull in Linq?
- Is there a good source that gives an overview of linq optimizations?
- Get the last 100 inserted records in sql server
- SQL Connection Remains Open when using DataContext