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 7646541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:14:10+00:00 2026-05-31T10:14:10+00:00

I need to manage hierarchy data storing in my database. But now I am

  • 0

I need to manage hierarchy data storing in my database. But now I am facing a problem. I am using entity sql for my asp.net. So now, how can I convert those sql to entity query? Here is the SQL query I suppose converts to entity framework query

      WITH RPL ( P_TASK_ID, C_TASK_ID,taskSeq) AS
     (  SELECT  root.P_TASK_ID, root.C_TASK_ID ,root.Seq
        FROM [COMMON.TASK_REL_test] as root
      UNION ALL
        SELECT  child.P_TASK_ID, child.C_TASK_ID, child.Seq
        FROM [COMMON.TASK_REL_test] parent, [COMMON.TASK_REL_test] child
        WHERE  parent.C_TASK_ID = CHILD.P_TASK_ID
     )
SELECT DISTINCT P_TASK_ID, C_TASK_ID,taskSeq
 FROM RPL
  ORDER BY  P_TASK_ID, C_TASK_ID,taskSeq; 

Here is my table structure

   pID  CID   Seq
   NULL 1   1
    1   2   1
    1   3   2
    1   4   3
    2   5   1
    2   6   2
    3   7   1

Here is my insert table query

INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID, Seq)
values (null,1,1)


INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID,Seq)
values (1,2,1)


INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID,Seq)
values (1,4,3)


INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID,Seq)
values (1,3,2)


INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID,Seq)
values (2,6,2)

INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID,Seq)
values (2,5,1)

INSERT into [COMMON.TASK_REL_test](P_TASK_ID,C_TASK_ID,Seq)
values (3,7,1)

Here is my coding

 private void createGridView()
        {
            try
            {


                using (ObjectContext ctx = new ObjectContext(gbcDbConnection.eObjqueryConnection))
                {
                    string result = @"
                                ;WITH RPL ( P_TASK_ID, C_TASK_ID,taskSeq) AS
                                (  SELECT  root.P_TASK_ID, root.C_TASK_ID ,root.Seq
                                   FROM LEWREDBEntities.[COMMON_TASK_REL_test] as root
                         UNION ALL
                                SELECT  child.P_TASK_ID, child.C_TASK_ID, child.Seq
                                 FROM LEWREDBEntities.[COMMON_TASK_REL_test] as parent, LEWREDBEntities.[COMMON_TASK_REL_test] as child
                        WHERE  parent.C_TASK_ID = CHILD.P_TASK_ID
                    )
                         SELECT DISTINCT P_TASK_ID, C_TASK_ID,taskSeq
                         FROM RPL
                         ORDER BY  P_TASK_ID, C_TASK_ID,taskSeq";
                    ObjectQuery<DbDataRecord> query = ctx.CreateQuery<DbDataRecord>(result);
                    string cde = query.ToTraceString();
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }

        }

But I am getting an error now.
The query syntax is not valid. Near term ‘;’, line 2, column 34..
Please help.

  • 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-31T10:14:12+00:00Added an answer on May 31, 2026 at 10:14 am

    Missing ;

    string result = " ; WITH RPL
    

    edit

    Well, ok, I googled a bit and the problem is CreateQuery uses EntitySql syntax, not T-SQL, so here the problem.

    You can use ExecuteStoreQuery method:

    string result = @" ... "
    
     var query = ctx.ExecuteStoreQuery<Result>(result);
    

    Where result is a class mapped to the projected columns:

    public class Result
    {
      public int P_TASK_ID {get; set;}
      ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to manage hierarchy data storing in my database. But I have a
I need to manage hierarchy data storing in my database. But I have a
I need to manage the trace files for a database on Sql Server 2005
I am working with ASP.NET and need to manage with a string typed by
We need to find a sensible way to manage our in-house .NET libraries that
i have got 24 buttons in my project.I need to manage them but I
I'm using a UINavigationController to manage my UIViewControllers hierarchy. For one of these UIViewController,
I need to manage (parse and build) XML in my c++ application but I
I need to manage a configuration file in Linux using a shell script, that
We have a need to manage our DNS records (add/update) remotely using C#... I

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.