我在C#MVC Web应用程序中有两个DTO类,我需要返回一个从一个类生成的列表,其中列出了第一个列表中的第二个数据列表。(思考嵌套数组,例如[0 [a,b],1 [a,b,c],2 [a,b,c,d],3,[a]等...])
)这是针对内部应用程序,在该应用程序中,工作人员会教育其他人有关其工作角色。
以下是我到目前为止的
//Abstract code representative of end goal
var foo = from x in _fooCtx.Foo
where (x.Condition1 && x.Condition2 && x.Condition3 && x.Condition4 > 0)
select new Models.ResourceDTO()
{
FirstName = x.FirstName,
LastName = x.LastName,
ResourceID = x.ResourceID,
};
//currently loops through each memeber of staff in list above and grabs their wamits history.
foreach (var foobar in foo)
{
int foobarID = foo.ResourceID;
var bar = from u in _barCtx.BarViews
where (u.PupilID == foobarID || u.TeacherID == foobarID)
select new Models.ApplicationDTO()
{
pupilName = u.Pupil,
teacherName = u.Teacher,
appDate = u.appDate.ToString(),
appID = u.ID,
};
var leaderList = bar.ToList();
}
上述可以在获取活跃的员工列表中,然后循环浏览他们可能参加的任何会议。我需要返回每个成员在foreach循环中选择第二个DTO生成的列表的员工列表。因此,foo数据列表,在此列表中,在此列表中。如果这是有道理的。
创建自定义DTO
Public class test
{
// add required properties along with list of ApplicationDTO
// so it will be something like this (getter setters)
FirstName
LastName
ResourceID
List<ApplicationDTO>
}
然后您可以创建此测试类的列表并使用
P.S:这只是一个示例示例,可以帮助您了解如何实现此
您可以使用Union
与相同类型的两个DTO附加。
这将合并两个DTO:
Dto1.Union(Dto2);