gpt4 book ai didi

c# - 使用 IEnumerable 过滤选择输出的 LINQ

转载 作者:行者123 更新时间:2023-11-30 18:16:54 26 4
gpt4 key购买 nike

我有以下方法:

Controller :

...
var appmap = Services.GetReqAppMapList(value);
var applist = Services.GetApplicationList(docid, appid, reqid, appmap);
...

型号:

public static IEnumerable<AppMap> GetReqAppMapList(int aiRequestTypeId)
{
try
{
var appmap = new List<AppMap>();
using (var eties = new eRequestsEntities())
{
appmap = (from ram in eties.ReqAppMaps
where ram.IsActive == 1
select new AppMap
{
RequestTypeId = ram.RequestTypeId
}).ToList();
return appmap;
}
}
catch(Exception e)
{
throw e;
}
}

public static IEnumerable<TicketApplication> GetApplicationList(int aiDocumentTypeId, int aiApplicationTypeId, int aiRequestTypeId, IEnumerable<AppMap> appmap)
{
try
{
var applicationlist = new List<TicketApplication>();
using (var applicationentity = new eRequestsEntities())
{
applicationlist = (from app in applicationentity.Applications
where 1==1
<<<Some Conditions Here???>>>
== && appmap.Contains(app.ApplicationTypeId) ==
&& app.IsActive == 1
select new TicketApplication
{
ApplicationId = app.ApplicationId,
Description = app.Description,
DeliveryGroupId = app.DeliveryGroupId,
ApplicationTypeId = app.ApplicationTypeId,
DeliveryTypeId = app.DeliveryTypeId,
DocumentTypeId = app.DocumentTypeId,
SupportGroupId = app.SupportGroupId
}).OrderBy(a => a.Description).ToList();

return applicationlist;
}

我在想如何使用 GetReqAppMapList 的结果过滤 GetApplicationList 的查询结果

我有点坚持我必须将某些东西转换/转换为正确类型的事实,因为每次我执行 result.Contains(准确地说是 appmap.Contains)时,我总是会收到以下错误

Error 4 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<Test.Models.AppMap>' to 'System.Linq.ParallelQuery<int?>'

最佳答案

您应该在一个查询中直接连接两个表。

using (var applicationentity = new eRequestsEntities())
{
applicationlist = (from app in applicationentity.Applications
join ram in applicationentity.ReqAppMaps on app.ApplicationTypeId equals ram.RequestTypeId
where ram.IsActive == 1 && app.IsActive == 1
select new TicketApplication
{
ApplicationId = app.ApplicationId,
Description = app.Description,
DeliveryGroupId = app.DeliveryGroupId,
ApplicationTypeId = app.ApplicationTypeId,
DeliveryTypeId = app.DeliveryTypeId,
DocumentTypeId = app.DocumentTypeId,
SupportGroupId = app.SupportGroupId
}).OrderBy(a => a.Description).ToList();

如果不再需要,您可以删除其他方法。没有必要卡在死代码上。

关于c# - 使用 IEnumerable<T> 过滤选择输出的 LINQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45412587/

26 4 0