I'm trying to do a very stupidly basic LINQ query on my Entity Framework context. It goes something like this:
var query = from e in context.Entity1s.Include("Entity2")
where e.Id == someVar.E1Id
select e;
As you can see, a stupidly basic, practically copy-paste-out-of-the-textbook query. But Visual Studio puts a red squiggly underline on the 'where' keyword, and I get a build error that looks like:
Delegate '
System.Func<Entity1, int, bool>' does not take 1 arguments
I can't make heads or tails of it. Can anyone explain what's going on?
After much semi-random tinkering, I fixed this problem. I'm not sure why I had to do this now, when I've never had to before, and I'm not completely sure why on earth this fixed it, or how the heck it has anything to do with the error I was getting, but I solved it like this:
// --->Added This<--
var query = from Entity1 e in context.Entity1s.Include("Entity2")
where e.Id == someVar.E1Id
select e;
Turned e into a strongly declared type instead of making Visual Studio deduce its type at compile time like I should be able to. Oh well. Not a big deal. No reason I would ever NOT be able to declare e's type.
Still it IRRITATES the HECK out of me that I didn't really solve this. I mean, I got it to work, but WHY? Why did what I do make a difference? Especially when it never used to matter?
I'll choose my answer here as the correct one, since it solves the issue, but if anyone has information to expound on the "why it worked" aspect, please leave comments. I'm sure I'm not the only person who would love to learn more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With