mohammad qasim

mohammad qasim

  • NA
  • 408
  • 0

Select all columns but group by only one in linq,How to Get only Id fr

Sep 14 2020 1:59 PM
Greetings
 
I am using Sharepoint 2016 on Prem
 
I want to Select all columns but apply "group by" only one using LINQ ( retrieve data from Sharepoint list )
 
Problem : Currently having 2 problems/challenges
 
Problem 1: I have lookup field which returns id with name like "23;#abcd" , for this I have to split to get Id only ( mention in below code using split(';').
 
Problem 2: in LINQ query ,I want to select stautus and documentname columns from list not on "group by".
 
Group by is just for 1 column like we do in sql server like below as
 
stautus and documentname feilds are not available in group by so unable to select these 2 fields
  1. select id,stautus ,documentname,comments from abc groupby userFk
My Code:
  1. oQuery.Query = "<Where><Eq><FieldRef Name='Flag'/><Value Type ='number'>" + 1 + "</Value></Eq></Where> ";  
  2. var resultfoldeDoc11 = (from SPListItem itm in pLis.GetItems(oQuery)  
  3. orderby itm["ID"]  
  4. group itm by new { m_folderID22 = itm["DocumentFolderFk"] } into g  
  5. select new { m_folderId22 = g.Key.m_folderID22.ToString().Split(';'), m_totaldocsfoldercount = g.Count() });  
Solution Required:for Both Problem
 
How can I select multiple columns in select clause with one field in "Groupby " Clause ?
 
How can I get only ID from Look up field in LINQ
 
Thanks

Answers (1)