Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile my project with LINQ syntax

I have been using Entity Framework and now wanted to query with LINQ code. I assumed that my code would just compile if i copied it almost verbatim from my reference book "Entity Framework 4 In Action".

here is my code:

from a in db.addresses
where a.accountId == 1
Select o;

unexpectedly, intellisense did not accept any of my code. So I did a little research and added projects references, web.config assembly reference and using reference to LINQ

using System.Data.Linq;

and have edited web.config to include

<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

Even Still, Intellisense and the compiled do not accept the keyword "in" or db.addresses (db is the context and elsewhere in my file i have no problem making calls like:

users currentUser = db.users.Single(m => m.email == User.Identity.Name);

so the problem is NOT my db context either. I've searched stack, asp.net, and googled "LINQ syntax not compiling" but can't find any further clue.

here are my compiler errors:

Error 14 ; expected 147 20 AdamsStore

Error 15 ; expected 147 23 AdamsStore

Error 16 ; expected 148 23 AdamsStore

Error 17 ; expected 148 39 AdamsStore

Error 13 Invalid expression term 'in' 147 20 AdamsStore

Error 8 Only assignment, call, increment, decrement, and new object expressions can be used as a statement 147 18 AdamsStore

Error 10 Only assignment, call, increment, decrement, and new object expressions can be used as a statement 148 23 AdamsStore

Error 7 The type or namespace name 'from' could not be found (are you missing a using directive or an assembly reference?) 147 13 AdamsStore

Error 11 The type or namespace name 'select' could not be found (are you missing a using directive or an assembly reference?) 149 21 AdamsStore

like image 256
Renaissance Avatar asked Dec 04 '25 18:12

Renaissance


1 Answers

  1. select needs to be lowercase
  2. You still need using System.Linq even if you have using System.Data.Linq
like image 82
Adam Avatar answered Dec 07 '25 22:12

Adam