我有一个记录(周和年)以及这些在数据库记录中有数据,想要在控制器上的方法中使用 LINQ 语句对查询执行相同的操作。如何为这些记录创建动态查询?记录(年和周)它们返回随机值,而不是与数据库表中的记录一起在接收器中。我怎样才能动态地实现这一点?我是否创建一个参数来动态获取值?
[HttpGet]
public IList<ExtractionViewModel> GetExtractionViewModels()
{
ProductionmanagementEntities db = new ProductionmanagementEntities();
var scheduleList = (from p in db.ProductionDays
from m in db.Models
from mx in db.Models
from mb in db.Models
from ml in db.Models
join w in db.Weeks on p.WeekId equals w.WeekId
orderby w.Year ascending
orderby m.Name ascending
where (m.Inactive == true)
where (mx.Inactive == false)
where (mb.Inactive == false)
where (ml.Inactive == false)
// how to get a year back in linq and week?
select new ExtractionViewModel
{
Year = w.Year,Week = w.WeekNum,Day = p.ProductionDate,VW250 = m.Name,VW270 = mx.Name,VW2502PA = mb.Name,VW270PA = ml.Name
}).ToList();
return scheduleList;
}
// Model
public class ExtractionViewModel
{
public string Year { get; set; } // how to get this back to linq stament?
public int Week { get; set; } // How to get this back on linq statement?
public DateTime Day { get; set; }
public string VW250 { get; set; }
public string VW270 { get; set; }
public string VW2502PA { get; set; }
public string VW270PA { get; set; }
}
// SQL Query
SELECT TOP (1000) [ModelId],[Name],[Code],[CreatedDate],[CreatedBy],[ModifiedDate],[ModifiedBy],[Inactive]
FROM [Productionmanagement].[Schedule].[Model]
SELECT TOP (1000) [WeekId],[WeekNum],[Year],[Inactive]
FROM [Productionmanagement].[Schedule].[Week]