7

I have two linq queries. I want to use result of one query in another query.

var t2s = (from temp3 in _ent.Products where temp3.Row_Num == 2 select new { temp3.ProductID }); 

Then I use this var in another query:

var _query = (from P1 in _ent.brands join temp2 in on new { Produ_ID = (Int32?)P1.Prod_ID } equals new { Produ_ID = (Int32?)temp2.ProductID } ); 

When I run the first query by itself it gives me the right result. If I run the second one without a join it gives me right result, but with a join gives me the following error:

error: Unable to create a constant value of type 'Anonymous type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context

1
  • 4
    Where's the t2s in second query? Commented Apr 10, 2013 at 19:54

2 Answers 2

3
+50

Are you sure you need a join? What about this:

var t2s = _ent.Products.Where(t => t.Row_Num == 1).Select(t =>t.ProductID); var _query = _ent.brands.Where(b => t2s.Contains(b.Prod_ID)); 

You may need to change things slightly depending on whether ProductID and/or Prod_ID are nullable.

Sign up to request clarification or add additional context in comments.

Comments

2

Try changing your queries as follows:

var t2s = from temp3 in _ent.Products where temp3.Row_Num == 2 select temp3.ProductID; var _query = from P1 in _ent.brands join temp2 in t2s on P1.Prod_ID equals temp2 select ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.