locked
LINQ Design time compile error RRS feed

  • Question

  • Can someone please inform me what the correct syntax is for the below query?

    I get a design time compile error beginning at the "equals" keyword at the following spot:

    && a.applicationid equals ga.applicationid

    with the following error: "A query body must end with a select clause or group clause"

    I understand what the error means, but I can't see what the syntax error is....

    public static List<ApplicationConfigurations> GetAppConfigs()
            {
                try
                {
                    using (wmswebEntities DbContext = new wmswebEntities())
                    {
                         IEnumerable<ApplicationConfigurations> myAppConfigs = new IEnumerable<ApplicationConfigurations>();
    
                         myAppConfigs = (from a in DbContext.ApplicationConfigurations
                                         join ga in DbContext.groupapplicationconfigurationslk on a.configurationid equals ga.configurationid
                                         && a.applicationid equals ga.applicationid
                                         join g in DbContext.Groups on g.groupnumber equals ga.groupnumber
                                         where a.ActiveFlag == true
                                            && ga.ActiveFlag == true
                                            && g.ActiveFlag == true
                                        select
                                            a.applicationconfigurations,
                                            g.groupnumber).ToList();
    
                        return myAppConfigs;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }


    Bill Yeager

    Sunday, February 17, 2013 4:55 PM

Answers

  • Hi Bill;

    Please try it like this.

    public static List<ApplicationConfigurations> GetAppConfigs()
    {
        try
        {
            using (wmswebEntities DbContext = new wmswebEntities())
            {
                 IEnumerable<ApplicationConfigurations> myAppConfigs = new IEnumerable<ApplicationConfigurations>();
    
                 myAppConfigs = (from a in DbContext.ApplicationConfigurations
                                 join ga in DbContext.groupapplicationconfigurationslk on new { a.configurationid, a.applicationid } equals new { ga.configurationid, ga.applicationid }
                                 join g in DbContext.Groups on g.groupnumber equals ga.groupnumber
                                 where a.ActiveFlag == true
                                    && ga.ActiveFlag == true
                                    && g.ActiveFlag == true
                                select
                                    a.applicationconfigurations,
                                    g.groupnumber).ToList();
    
                return myAppConfigs;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by Alexander Sun Monday, February 18, 2013 1:37 AM
    • Marked as answer by Alexander Sun Monday, March 11, 2013 4:13 PM
    Sunday, February 17, 2013 6:47 PM

All replies

  • Hi,

    Not tested bu likely you are misssing the new keyword (see http://msdn.microsoft.com/en-us/library/vstudio/bb397914.aspx "Selecting a subset of each source element")

    Or do you just want to list of ApplicationConfigurations in which case g.groupnumber should not be part of the select clause ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Sunday, February 17, 2013 5:20 PM
  • Hi Bill;

    Please try it like this.

    public static List<ApplicationConfigurations> GetAppConfigs()
    {
        try
        {
            using (wmswebEntities DbContext = new wmswebEntities())
            {
                 IEnumerable<ApplicationConfigurations> myAppConfigs = new IEnumerable<ApplicationConfigurations>();
    
                 myAppConfigs = (from a in DbContext.ApplicationConfigurations
                                 join ga in DbContext.groupapplicationconfigurationslk on new { a.configurationid, a.applicationid } equals new { ga.configurationid, ga.applicationid }
                                 join g in DbContext.Groups on g.groupnumber equals ga.groupnumber
                                 where a.ActiveFlag == true
                                    && ga.ActiveFlag == true
                                    && g.ActiveFlag == true
                                select
                                    a.applicationconfigurations,
                                    g.groupnumber).ToList();
    
                return myAppConfigs;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by Alexander Sun Monday, February 18, 2013 1:37 AM
    • Marked as answer by Alexander Sun Monday, March 11, 2013 4:13 PM
    Sunday, February 17, 2013 6:47 PM
  • Fernando, I see how you changed the "&&" in the query and understand. For a join expression, is that not allowed ("&&") if I have to add an "AND" condition to it?

    I tried your code snippet, and got past that, but am now getting the following errors on the select:

    On the comma, am getting this error: Invalid expression term ","

    On the right parenthesis, am getting this error: Invalid expression term ")"

    Note that if I only include one item in the select clause without a comma, it's fine...

    select
                                    a.ApplicationConfigurations,
                                    g.groupnumber).ToList();

    Bill Yeager

    Sunday, February 17, 2013 7:09 PM
  • A person from Stackoverflow answered the question at this link: http://stackoverflow.com/questions/14923491/linq-design-time-compile-error

    I used the following with no syntax errors. Since the GroupNumber is inside my ApplicationConfigurations class (after I mapped it on the edmx designer), that's all I needed in the select.

    You were right except for the select, but I gave you points for it anyway. You've been very helpful; thanks...

    var AppConfigs = from a in DbContext.ApplicationConfigurations
                                 join ga in DbContext.groupapplicationconfigurationslk on new { a.configurationid, a.applicationid } equals new { ga.configurationid, ga.applicationid }
                                 join g in DbContext.Groups on g.groupnumber equals ga.groupnumber
                                 where a.ActiveFlag == true
                                    && ga.ActiveFlag == true
                                    && g.ActiveFlag == true
                                select
                                    a;
    
                 IEnumerable<ApplicationConfigurations> myAppConfigs = new IEnumerable<ApplicationConfigurations>();
    
                   myAppConfigs = AppConfigs.ToList();
    
                return myAppConfigs;


    Bill Yeager

    Sunday, February 17, 2013 10:09 PM
  • The second part of your answer was what I was looking for. You are correct; thanks...

    Bill Yeager

    Sunday, February 17, 2013 10:10 PM