Linq Compiling Issue

Last post 09-30-2008 3:47 AM by rjcox. 5 replies.

Sort Posts:

  • Linq Compiling Issue

    09-26-2008, 6:18 PM
    • Member
      point Member
    • joero42
    • Member since 09-26-2008, 10:14 PM
    • Posts 3

    I can't figure out what is going on here.  I am using linq to query my sql database.  If I set my code to be a "CodeFile", then I get the following error...

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1002: ; expected

    Source Error:


    Line 57:             DataDataContext _db = new DataDataContext();
    Line 58:
    Line 59: var _devices = from d in _db.empact_Devices
    Line 60: where d.empact_DeviceType.DeviceTypeName == "Buoy"
    Line 61: select d;
     

    If I change it to a "CodeBehind" and compile my project, then the page renders fine. Any reason why this would be happening?  Most of my other pages are CodeFile pages.  

     

    Thanks,

    Joe 

  • Re: Linq Compiling Issue

    09-27-2008, 12:32 PM
    • All-Star
      36,220 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,819

     Just a guess but are you importing the linq namespaces in your codefile page? Maybe if it doesnt have the namespace then its tripping up the compiler trying to parse the code?

    What about if you rewrite it the other way (forgot the name) like

    var _devices = _db.empact_Devices.Select(d => d.empact_DeviceType.DeviceTypeName == "Buoy");

  • Re: Linq Compiling Issue

    09-27-2008, 4:53 PM
    • Member
      point Member
    • joero42
    • Member since 09-26-2008, 10:14 PM
    • Posts 3

    Thanks for responding.  I re-wrote the query and got the following error...
     

    Compiler Error Message: CS1525: Invalid expression term '>'

     Also these are the namespaces I have been using...

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    Thanks,

    Joe
     

  • Re: Linq Compiling Issue

    09-28-2008, 4:46 AM
    Answer
    • Contributor
      7,054 point Contributor
    • rjcox
    • Member since 12-19-2007, 9:14 AM
    • Basingstoke, UK
    • Posts 1,444

    joero42:
    Invalid expression term '>'
     

    There is no ">" in your code (above)... you'll need to show the current version (use cut & paste, not retyping it).

    Also, for LINQ to SQL (use of  DataContext), you will need the namespace System.Data.Linq.

    Richard
  • Re: Linq Compiling Issue

    09-29-2008, 2:21 PM
    • Member
      point Member
    • joero42
    • Member since 09-26-2008, 10:14 PM
    • Posts 3

    I didn't cut and paste it in because it didn't help me solve my problem.  It still works fine if the page is compiled as code-behind and not as a code-file.  So no matter what way you write the query it still failed when used in a code file.  I am not using a DataContext, as I'm not using Linq to SQL.  I'm simply querying a collection. 

     Thanks,

    Joe
     

  • Re: Linq Compiling Issue

    09-30-2008, 3:47 AM
    • Contributor
      7,054 point Contributor
    • rjcox
    • Member since 12-19-2007, 9:14 AM
    • Basingstoke, UK
    • Posts 1,444

    joero42:
    I am not using a DataContext, as I'm not using Linq to SQL. 
     

    We will not be able to help without a complete, but short, recreate, because the errors you are asking for help with do not relate to the code samples you have posted (and you have not defined things, so we have to guess from the names).

    Richard
Page 1 of 1 (6 items)