gpt4 book ai didi

c# - 向模型存储库发送查询

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:40 25 4
gpt4 key购买 nike

请帮忙。我是 ASP.NET MVC 的新手,我正在尝试向存储库发送查询,但它给了我一个错误:

Errr 3 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IList'. An explicit conversion exists (are you missing a cast?)

我正在使用一个架构类,其中只有我需要的列。这是我用于存储库的代码。

public class SSGridRepository : SSGridIRepository
{
private DataClassesSSDataContext db;

public SSGridRepository()
{
db = new DataClassesSSDataContext();
}

public IList<SSQuerySchema> ListAll()
{

var SSQuery = (from HISTORies in db.HISTORies
join SSes in db.SSes on HISTORies.WO equals SSes.WO
join SSCUSTOMs in db.SSCUSTOMs on SSes.WO equals SSCUSTOMs.WO
join StatusTables in db.StatusTables on new { STATUS = SSes.STATUS } equals new { STATUS = StatusTables.Status }
join StatusTable_1 in db.StatusTables on new { OLDSTATUS = HISTORies.OLDSTATUS } equals new { OLDSTATUS = StatusTable_1.Status }
join StatusTable_2 in db.StatusTables on new { NEWSTATUS = HISTORies.NEWSTATUS } equals new { NEWSTATUS = StatusTable_2.Status }
where
HISTORies.OLDSTATUS == "m" &&
HISTORies.NEWSTATUS == "n" &&
HISTORies.ACTION == "Change Job Status" &&
HISTORies.OLDSTATUS != HISTORies.NEWSTATUS &&
HISTORies.DATE.Value.Year == Convert.ToDateTime(DateTime.Now).Year ||
HISTORies.OLDSTATUS != HISTORies.NEWSTATUS &&
HISTORies.NEWSTATUS == "m" &&
HISTORies.ACTION == "Checked In Work Order" &&
HISTORies.DATE.Value.Year == Convert.ToDateTime(DateTime.Now).Year
orderby
HISTORies.DATE
select new
{
HISTORies.WO,
SSes.TITLE,
SSes.DESCRIPT,
SSCUSTOMs.CUSTNAME,
SSes.STAKER,
HISTORies.USER,
SSes.STATUS,
HISTORies.OLDSTATUS,
HISTORies.NEWSTATUS,
CURRENT_STATUS = StatusTables.Description,
OLD_STATUS = StatusTable_1.Description,
NEW_STATUS = StatusTable_2.Description,
HISTORies.DATE.Value.Month,
HISTORies.DATE
}).Distinct();
return SSQuery.ToList();
}
}

最佳答案

在你的 Linq 中你这样做:

select new  {
HISTORies.WO,
SSes.TITLE,
SSes.DESCRIPT,
SSCUSTOMs.CUSTNAME,
SSes.STAKER,
HISTORies.USER,
SSes.STATUS,
HISTORies.OLDSTATUS,
HISTORies.NEWSTATUS,
CURRENT_STATUS = StatusTables.Description,
OLD_STATUS = StatusTable_1.Description,
NEW_STATUS = StatusTable_2.Description,
HISTORies.DATE.Value.Month,
HISTORies.DATE
}

这是一个动态类型,所以它不会匹配你的返回类型 List<SSQuerySchema>

尝试初始化您在 Linq 中指定的类型并设置属性。

  select new SSQuerySchema {
// initialize all properties here
}

关于c# - 向模型存储库发送查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22366605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com