title: Entity query select top1
body: <p>i having problem in sql by using <strong>ExecuteStoreQuery</strong> Please see the example at below</p>
  
  <p>My coding </p>
  
  <pre><code>  private void ChildMenuItem()
      {
          using (LEWREDBEntities ctx = new LEWREDBEntities())
          {
              string result = @"
  
                  WITH ctLevel
                  AS
                  (
                      SELECT
                          C_TASK_ID                                                               AS Child
                          ,P_Task_ID                                                              AS Parent
                          ,common_task.   TASK_SEQ                                                AS taskSeq
                          ,1                                                                      AS [Level]
                          ,CAST( TASK_SEQ AS VARCHAR(MAX))                                        AS [taskOrder]
                          ,CAST (Replicate('', 1) + common_task.TASK_NAME AS VARCHAR(MAX))        AS [Task_Name]
                      FROM   
                          [COMMON.TASK_REL] as common_task_rel, 
                          [COMMON.TASK] as common_task
                      WHERE  
                          common_task_rel.C_TASK_ID = common_task.TASK_ID
                          and     common_task.[TASK_TYPE] = 'F' AND common_task.[MODULE_CODE] = 'PRODE' AND common_task.[STATUS] &lt;&gt; 'D'
                          and C_TASK_ID =357
  
                      UNION ALL
  
                      SELECT 
                          C_TASK_ID                                                                   AS Child
                          ,P_Task_ID                                                                  AS Parent
                          ,common_task.   TASK_SEQ                                                    AS taskSeq
                          ,[Level] + 1                                                                AS [Level]
                          ,[taskOrder] + '.' + CAST(TASK_SEQ AS VARCHAR(MAX))                         AS [taskOrder]
                          ,CAST (Replicate('', [Level] + 1) + common_task.TASK_NAME AS VARCHAR(MAX))  AS [Task_Name]
                      FROM   
                          [COMMON.TASK_REL]as common_task_rel
                      INNER JOIN 
                          ctLevel
                      ON 
                          ( P_Task_ID = Child ) ,
                          [COMMON.TASK] as common_task
  
                      WHERE  
                              common_task_rel.C_TASK_ID = common_task.TASK_ID
                      and     common_task.[TASK_TYPE] = 'F' AND common_task.[MODULE_CODE] = 'PRODE' AND common_task.[STATUS] &lt;&gt; 'D'
                      )
  
                     SELECT 
                     common_task.Task_Name,
                     common_task_url.TASK_URL,
                     ctLevel.CHILD
  
                      FROM   
                      ctLevel,
                      [COMMON.ACL] as common_acl,
                      [COMMON.STAFF_ROLE] as common_staff_role,
                      [COMMON.TASK_URL] as common_task_url,
                      [COMMON.TASK] as common_task,
                      [COMMON.STAFF_MODULE] as common_staff_module,
                      [common.module] as common_module
  
                      where ctLevel.Level =3
                      and ctLevel.Child = common_acl.TASK_ID
                      and common_acl.READ_ACCESS ='Y'
                      and common_acl.STATUS &lt;&gt;'D'
                      and common_acl.ROLE_ID = common_staff_role.ROLE_ID
                      and common_staff_role.STATUS &lt;&gt;'D'
                      and common_staff_role.STAFF_ID ='user'
                      and common_staff_role.STAFF_ID = common_staff_module.STAFF_ID
                      and common_staff_module.MODULE_CODE =common_module.MODULE_CODE
                      and common_staff_module.STATUS&lt;&gt;'D'
                      and common_staff_module.MODULE_CODE = common_module.MODULE_CODE
                      and common_module.STATUS &lt;&gt;'D' and common_module.MODULE_CODE ='PRODE'
                      and common_acl.TASK_ID = common_task.TASK_ID
                      and common_task.STATUS &lt;&gt;'D'
                      and common_task.TASK_TYPE ='F'
                      and common_task.TASK_POSITION ='S'
                      and common_task.TASK_ID = common_task_url.TASK_ID
                      and common_task_url.DEFAULT_URL ='Y'
                      and common_task_url.STATUS&lt;&gt;'D'
  
  
                      Group By    
                               [taskOrder],common_task.Task_Name, TASK_URL,ctLevel.CHILD
  
                      order by [taskOrder],common_task.Task_Name, TASK_URL,ctLevel.CHILD";
  
              var query = ctx.ExecuteStoreQuery&lt;dlcGvTask&gt;
                  (result);
  
  
              foreach (dlcGvTask gvTask in query.ToList())
              {
                  MenuItem navigation = new MenuItem(gvTask.TASK_NAME, gvTask.Child.ToString(), "","");
                  MenuChild.Items.Add(navigation);
              }
  
            //Here????
              var id = (from table in query
                        select table.Child).Take(1);
  
              ;
  
          }
  
      }
  </code></pre>
  
  <p>Now i got a question.How can i select the top 1 of the Record?</p>