1 Replies - 1435 Views - Last Post: 14 July 2012 - 07:10 AM Rate Topic: -----

#1 xikky  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 19-December 09

LINQ to Entities: search query using different datatypes

Posted 14 July 2012 - 02:59 AM

For a search query by string, I use the following code to search for records, in this case within the Entity Courses.

in the below example, code and title are 2 string variables.
var list = from course in Entity.Courses
where ((code == "" || course.courseCode.Equals(code))
  && (title == "" || course.courseTitle.Equals(title))
select new Course();



But how do I go about to search by an int and a boolean?

If I use the same methods I get this error: DbComparisonExpression requires arguments with comparable types.

I tried .ToString(), .Value.ToString(), but all for nothing.

Is This A Good Question/Topic? 0
  • +

Replies To: LINQ to Entities: search query using different datatypes

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: LINQ to Entities: search query using different datatypes

Posted 14 July 2012 - 07:10 AM

Create a string variable using the int or bool and pass that string variable into your query.

var intToString = myInteger.ToString();

var list = from course in Entity.Courses
           where ((code == "" || course.courseCode.Equals(intToString))
                 && (title == "" || course.courseTitle.Equals(title))
           select new Course();



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1