tags:

views:

42

answers:

3

Hello,

I'm just looking to perform a LINQ query to return a group of course ID's and Course Titles which are running next year. As part of this I need to perform an OR query as I'm also looking to return data relating to next year as well which is held as a string in my databse and is the only issue I'm having, so any help would be appreciated.

var result = (
    from a in Offering
    join b in Courseinfo on a.CourseID equals b.CourseID
    into temp
    from c in temp
    where c.Year == "10/11" || "11/12"
    select new { c.CourseID, c.CourseTitle }).DefaultIfEmpty();
+5  A: 

Rewrite your query as where c.Year == "10/11" || c.Year == "11/12".

Anton Gogolev
Thanks, I had tried this but it was saying Operator '||' cannot be applied to operands of type 'bool' and type 'string'. However it now works so thanks.
manemawanna
+1  A: 

If you want to be able to dynamically select years then you could do something like this

var years = new List<string>{"1989", "1994", "2004", "2007"};

and then change the where to

where years.Contains(c.Year)
Jonas Elfström
+1  A: 

It's a basic syntax error - in C# you can't say:

"Where the year is 2010 or 2011".

You have to say:

"Where the year is 2010, or the year is 2011"

So you rewrite this:

where c.Year == "10/11" || "11/12"

as this:

where c.Year == "10/11" || c.Year == "11/12"
Neil Barnwell