C# 转换Linq语句以在抽象存储库模式中使用
这个Linq语句工作得非常好,只是我意识到我需要使用存储库和工作单元 所以我有一个Linq查询C# 转换Linq语句以在抽象存储库模式中使用,c#,linq,lambda,repository-pattern,C#,Linq,Lambda,Repository Pattern,这个Linq语句工作得非常好,只是我意识到我需要使用存储库和工作单元 所以我有一个Linq查询 var query = (from rg in ReportGroups join rd in ReportDefinitions on rg.ReportGroupID equals rd.ReportGroupID where rd.ReportGroupID == 5 select rg).Cou
var query = (from rg in ReportGroups
join rd in ReportDefinitions on rg.ReportGroupID equals rd.ReportGroupID
where rd.ReportGroupID == 5
select rg).Count();
我看到的是
object responseObject = null;
responseObject = _reportService.GetReportGroups("en-us").ToList();
responseObject = _reportService.GetReportDefinitions("en-us").Where(e => e.ReportGroupID == Convert.ToInt32(id)).ToList();
所以你可以看到,这就是我目前检索数据的方式
我想加入,但我不知道如何才能加入
我在考虑多个呼叫,许多for循环
此外,我还注意到如何使用lambda语句在不同的方法中调用现有服务
private IEnumerable<SelectListItem> GetActivityList()
{
return _activityService
.GetAllActivities()
.OrderBy(n => n.ActivityName)
.Select(a => new SelectListItem
{
Text = a.ActivityName,
Value = a.Id.ToString(CultureInfo.InvariantCulture)
});
}
private IEnumerable GetActivityList()
{
返回活动服务
.GetAllActivities()
.OrderBy(n=>n.ActivityName)
.选择(a=>new SelectListItem
{
Text=a.ActivityName,
Value=a.Id.ToString(CultureInfo.InvariantCulture)
});
}
我意识到人们看不到所有的底层数据抽象,我当然可以提供任何要求,我只是在使用Linqpad连接数据库并编写查询时有点困惑,但现在我意识到连接等。。使用服务层可能不是那么容易。请添加一些关于解决方案的注释,说明为什么以及如何解决问题。Include获取两个表,您可以通过提供条件来获得所需的详细信息。我不确定如何像这样使用DbSet,因此,如果我把它换掉,它不喜欢Include,那么ReportGroups和ReportDefinitions也是一个问题,return\u reportService.Include(x=>x.ReportGroups).Include(x=>x.ReportDefinitions).Where(id);如果报表定义是报表组的外键,并且必须给出x.id==33,则该条件有效
return DbSet.Include(x => x.ReportGroups )
.Include(x => x.ReportDefinitions ).Where(//id condition);