Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create a constant value of type 'Anonymous type'

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

like image 268
user1562231 Avatar asked Mar 22 '13 13:03

user1562231


1 Answers

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.

like image 168
Phil Avatar answered Sep 23 '22 10:09

Phil