0

I had the following method in a controller before moving it to its own class, and its complaining about s => s.LocationAssignment stating it cant change it from lambda to string because its a delgate.

Any one know what I have to change?

public static IEnumerable<Service> getAllService()
{
    using (var db = new LocAppContext())
    {
        var service = db.Locations.Include(s => s.LocationAssignment);

        var serv = (from s in db.Services
                    where s.active == true
                    select s).ToList();
        return serv;
    }
}
von v.
  • 16,868
  • 4
  • 60
  • 84
TheWebs
  • 12,470
  • 30
  • 107
  • 211
  • 1
    @LukeHennerley Depend where you're from, I'm sure people in the US don't find it offensive as it has a different context. Why has SO become such a hostile place now? – Paulie Waulie Apr 19 '13 at 15:41
  • @PaulieWaulie it's not a hostile place, why if you find it hostile in one country should you say it in another. A number of racial terms "aren't offensive" in one country, but are in another. If one person can get offended by the remark, for personal reasons then we shouldn't even consider condeming it – LukeHennerley Apr 22 '13 at 08:01
  • @LukeHennerley Because what he wrote wasn't even comparable to a racist comment, it was a flippant remark which only some people in the UK may find offensive (not sure where Kyle is from), others see it in a totally different context and do not even think of it the manner which you did. It was not a word I would choose to use but it's not one which I felt required a "telling off" for, may be a friendly piece of advice would have sufficed? – Paulie Waulie Apr 22 '13 at 08:27
  • @PaulieWaulie I hardly told the OP he was "grounded" I just said it's probably not the best choice of wording, which it isn't. If you can't agree with that then you must be deluded I am afraid. It is comparable to a racist comment, in that some words are racist in one origin or corner of the world but not another. The word in question, is infact offensive to some people in some countries. Seeing as SO is multilingual, it is common sense to say to change it, no? – LukeHennerley Apr 22 '13 at 08:32
  • @LukeHennerley I was not disagreeing with what you were saying, yes the word can be offensive to some people hence why I said I would never use it and why I thought it was fair to point it out but I felt that the manner in which you did was quite harsh that's all. I didn't know why you felt the need to be so pious. – Paulie Waulie Apr 22 '13 at 08:42
  • @PaulieWaulie that's fine then, nothing more to discuss - saying that the word isn't really the best way to describe something isn't at all harsh. Have a great day :) – LukeHennerley Apr 22 '13 at 08:51
  • @LukeHennerley You too :) – Paulie Waulie Apr 22 '13 at 09:05
  • possible duplicate of [Retrieving Property name from lambda expression](http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression) – TheWebs Feb 19 '15 at 07:05

3 Answers3

4

If you are using version 4 of EF then the Include method does not accept a lambda expression but rather a string. The error is really meaningful for your particular situation. This is the actual definition of the Include method in EF 4:

public DbQuery Include(string path)

So what you can do is this:

db.Locations.Include("LocationAssignment");
von v.
  • 16,868
  • 4
  • 60
  • 84
1

Just want to add that I received this error. I was missing the reference below, took me a while to figure as I'd have thought the error would have referred to missing a namespace directive or something, rather than the delegate not being convertible to a string.

using System.Data.Entity;
Sean T
  • 2,414
  • 2
  • 17
  • 23
-2

service is not used.

service is of type IQueryable<Locations>. The method returns IEnumerable<Service>

public static IEnumerable<Service> getAllService()
{
    using (var db = new LocAppContext())
    {
        // var service = db.Locations.Include(s => s.LocationAssignment);

        var serv = (from s in db.Services
                    where s.active == true
                    select s).ToList();
        return serv;
    }
}
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • That will fix his compiler error without remotely helping him understand why his call to `.Include` failed (missing a `using` clause: http://msdn.microsoft.com/en-us/library/gg696395%28v=vs.103%29.aspx) – Kirk Woll Apr 19 '13 at 15:25