Hi I am writing linq query to get data from multiple tables. I am trying to get array of objects as below.
processobject retObj = new processobject();
retObj =(from c in entityObject.NCT_Process
join user in entityObject.NCT_UserRegistration on c.createdUserId equals user.User_Id
join file in entityObject.NCT_FileUpload on c.iconfileId equals file.upld_ID
join templObj in entityObject.NCT_Templates on c.ID equals templObj.processId
where c.processid == "10"
select new processobject
{
id = c.ID,
code = c.code,
flochartContent = c.flowchartContent,
//arrayofTemplates array i want to return
}
);
public class processobject
{
public templatesObject[] arrayofTemplates { get; set; }
public int id { get; set; }
public string flochartContent { get; set; }
public string code { get; set; }
}
In the above query i have written condition where c.processid == "10". so there are multiple records exists in NCT_Templates with processid 10. I want to return array with all those records. I have created array as below in my custom class.
I have this query
processobject retObj = new processobject();
retObj = (from c in entityObject.NCT_Process
join user in entityObject.NCT_UserRegistration on c.createdUserId equals user.User_Id
join file in entityObject.NCT_FileUpload on c.iconfileId equals file.upld_ID
into filesObjFirst
from wt1 in filesObjFirst.DefaultIfEmpty()
join templObj in entityObject.NCT_Templates on c.ID equals templObj.processId
into filesObj
from wt in filesObj.DefaultIfEmpty()
where c.ID == dbObject.ID
select new processobject
{
id = c.ID,
code = c.code,
flochartContent = c.flowchartContent,
name = c.name,
parentId = c.parentId,
projectId = c.projectId,
objectives = c.objectives,
displayOrder = c.dispalyOrder,
iconFileId = c.iconfileId,
level = c.level,
iconFileobj = new iconFile
{
id = wt1.upld_ID,
name = wt1.fileName,
url = wt1.filePath
},
description = c.description,
startCriteria = c.startCriteria,
endCriteria = c.endCriteria,
reporting = c.reporting,
output = c.output,
kpi = c.kpi,
procedureHistory = c.procedureHistory,
role = c.role,
duration = c.duration,
owner = c.owner,
visibility = true,
createdUserId = c.createdUserId,
}).FirstOrDefault();
I have this one more query
templatesObject[] templatesobject = (from c in entityObject.NCT_Templates
where c.processId == dbObject.ID
join file in entityObject.NCT_FileUpload on c.templateFileId equals file.upld_ID
into filesObjFirst
from wt1 in filesObjFirst.DefaultIfEmpty()
select new templatesObject
{
id = c.id,
title = c.title,
version = c.version,
visible = c.visibility,
filesObj = new iconFileTemplate()
{
id = wt1.upld_ID,
url = wt1.filePath,
name = wt1.fileName
}
}).ToArray();
Inside arrayofTemplates I want to store records of NCT_Templates.
Any help would be appreciated. Thank you.