Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var itemOne = from n in db.TimeTable
              where n.CodeNo == code
              select n.CodeNo;
var itemTwo = from p in db.Address
              where (itemOne.Contains(p.AddCode))
              select p;

Got this error when run-
LINQ to Entities does not recognize the method 'Boolean Contains[Decimal](System.Linq.IQueryable`1[System.Decimal], System.Decimal)' method, and this method cannot be translated into a store expression.
Posted
Updated 19-Oct-11 8:37am
v2
Comments
kiran dangar 20-Oct-11 2:00am    
what are the datatypes of CodeNo & AddCode ??
divesh12 20-Oct-11 8:49am    
Decimal

1 solution

var itemOne is a Decimal. You say, at the end of the query for itemOne that it should select n.CodeNo. So you are selecting a Decimal, not a TimeTable (which I think you want to actually select).
In the itemTwo query you want to look where itemOne (a TimeTable Decimal.Contains(AddCode). Well, a Decimal does not have a Contains Function, so it will never find it!
C#
var itemOne = from n in db.TimeTable
              where n.CodeNo == code
              select n; // Not the n.CodeNo!
var itemTwo = from p in db.Address
              where (itemOne.Contains(p.AddCode))
              select p;

I think that will solve your problem. To make sure what the type of itemOne and itemTwo are hoover over the var keyword in front of it.
Hope that helps! :)
 
Share this answer
 
v2
Comments
divesh12 25-Oct-11 9:26am    
Its Not working friend.
Sander Rossel 25-Oct-11 10:05am    
var itemTwo = from p in db.Address
where (itemOne.Where(tt => tt.CodeNo = p.AddCode).Any)
select p;

Does that work? A simple Contains will not work. You should pass in an IComparer(Of TimeTable) in the Contains or solve it differently to check if there actually is an itemOne which Contains the p.AddCode.
And actually, coming to think of it, is itemOne a List or a single item?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900