Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:58:54+00:00 2026-05-29T04:58:54+00:00

I have a problem in my select statement in my query. This sql query

  • 0

I have a problem in my select statement in my query. This sql query works in SqlServer Management Studio and selects the requested data but in my class its gives me an error “The query syntax is not valid. Near term ‘*’, line 9, column 47.” then another error in my From Forums F clause thats after taking out LastPostBy, LastPostDate, LastPostTitle i also get an error in LastPostTitle but like I said it works in SQLServer Management Studio. I initally tried to do a “Exec sproc_Forums_GetForums” stored procedure and that didn’t work this is my first attempt using this approach in with Entities.
All my query is suppose to do is get a forum and display information from two tables named Forums and Posts

    public List<Forum> GetForums()
    {
        List<Forum> forums = null;
        using (EntityConnection conn = new EntityConnection("name=CMSEntities"))
        {
            conn.Open();
            string query = @"
                SELECT ForumGroup = (
                    CASE WHEN ParentID IS NOT NULL THEN
                        (SELECT Title FROM Forums WHERE ForumID = F.ParentID)           
                    ELSE
                        (SELECT Title FROM Forums WHERE ParentID IS NULL)
                    END),
                F.Title, F.Description, 
                ThreadCount = (SELECT COUNT(*) FROM Posts P WHERE P.ForumID = F.ForumID),
                LastPostBy = (SELECT TOP 1 AddedBy FROM Posts P WHERE P.ForumID = F.ForumID ORDER BY P.PostID DESC), 
                LastPostDate = (SELECT TOP 1 AddedDate FROM Posts P WHERE P.ForumID = F.ForumID ORDER BY P.PostID DESC),
                LastPostTitle = (SELECT TOP 1 Title FROM Posts P WHERE P.ForumID = F.ForumID ORDER BY P.PostID DESC)     
                FROM Forums F WHERE ParentID IS NOT NULL    
                ORDER BY Title
            ";
            EntityCommand cmd = new EntityCommand(query, conn);
            using (EntityDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
            {
                while (reader.Read())
                {
                    Forum forum = new Forum(
                        (int)reader["ForumID"],
                        "",
                        DateTime.Now,
                        reader["Title"].ToString(),
                        reader["Description"].ToString(),
                        0,
                        false,
                        null,
                        null,
                        null,
                        true,
                        reader["ForumGroup"].ToString(),
                        (int)reader["ThreadCount"],
                        reader["LastPostBy"].ToString(),
                        (DateTime)reader["LastPostDate"],
                        reader["LastPostTitle"].ToString());
                    forums.Add(forum);
                }
                return forums;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:58:55+00:00Added an answer on May 29, 2026 at 4:58 am

    This is not valid ESQL query. You cannot make SQL query in your SQL management and execute it as ESQL. ESQL is different query language with its own syntax which is close to SQL but still have differences because it doesn’t query database but entity model. For example simple query in ESQL looks like this:

    SELECT VALUE Entity FROM Namespace.Entities AS Entity WHERE Entity.SomeField = 10
    

    Do you see the difference to common SQL?

    Instead of using ESQL and EntityCommand use either SqlCommand to execute SQL query or ObjectContext.ExecuteStoreQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have a problem with this SQL query: SELECT * FROM appts
I have a problem with an SQL query on Postgresql. This select clause is
I have written a MDX query which works fine in SQL Server Management Studio.
I have a problem creating the following SQL Statement using LINQ & C# select
I have a problem with an SQL query. SELECT SUM(table_colum) AS value, SUM(value *
I have a problem with a query that works in phpmyadmin but not with
I am trying to solve this problem. I have a series of SELECT statements
i have a problem concerning a select query in MYSQL i have two different
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I have encountered a problem when trying to select data from a table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.