Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: entity
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 19-Oct-11 9:29am
Edited 19-Oct-11 9:37am
v2
Comments
kiran dangar at 20-Oct-11 2:00am
   
what are the datatypes of CodeNo & AddCode ??
divesh12 at 20-Oct-11 8:49am
   
Decimal

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
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! Smile | :)
  Permalink  
v2
Comments
divesh12 at 25-Oct-11 9:26am
   
Its Not working friend.
Naerling at 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)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 22 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100