我有以下3个表格,如下所示。我试图在3个表中编写实体框架连接查询
要追溯joblink, usersubmitted, runstatus, submitted_time, changelist orderby submitted time
。
我有一个持有者类来返回输出...请注意,gerrits是一个List<string>
,因为它可以为一次运行提供多个值,这是我得到错误的地方..,can任何人都提供了如何解决错误的指导,还是有更好的实践来实现这个目标?
持有人类: -
namespace Dashboard.Model.ApiModels
{
public class LookaheadRunInfo
{
public string ECJobLink { get; set; }
public List<String> changelists { get; set; }
public string UserSubmitted { get; set; }
public string SubmittedTime { get; set; }
public string RunStatus { get; set; }
}
}
API: -
public IEnumerable<LookaheadRunInfo> GetLookaheadRunInfoSearch(LookaheadRunsFilterCriteria filterCriteria)
{
List<LookaheadRunInfo> lookaheadRunsInfo = new List<LookaheadRunInfo>();
var lookaheadRunData = bitDB.lookahead_run.OrderByDescending(x => x.lookahead_run_id).Skip(filterCriteria.PageNumber * filterCriteria.PageSize).Take(filterCriteria.PageSize).ToList();
foreach (var lookaheadRunRow in lookaheadRunData)
{
var lookaheadRunId = lookaheadRunRow.lookahead_run_id;
var lookaheadRuns = new LookaheadRunInfo();
lookaheadRuns = (from lrcl in bitDB.lookahead_run_change_list
join cl in bitDB.change_lists on lrcl.change_list_id equals cl.change_list_id
join lr in bitDB.lookahead_run on lrcl.lookahead_run_id equals lr.lookahead_run_id
where lrcl.lookahead_run_id == lookaheadRunId
orderby lr.submission_time
select new LookaheadRunInfo
{
ECJobLink = lr.ec_job_link,
//gerrits = cl.change_lists.Select(x => x.change_list.ToString()).ToList(),
changelists = cl.change_list.ToString(),
UserSubmitted = lr.submitted_by,
SubmittedTime =lr.submission_time.ToString(),
RunStatus = lr.lookahead_run_status,
}).ToList();
lookaheadRunsInfo.Add(lookaheadRuns);
}
return lookaheadRunsInfo;
}
表: -
lookahead_run (Table#1)
+-------------------+--------+----------------+-------------------+----------+
lookahead_run_id(PK)|joblink | usersubmitted |submitted_time |runstatus
+-------------------+--------+----------------+-------------------+----------+
15963---------------+link1---+---username1----+2017-03-17 22:28:53--Fail-----
lookahead_run_change_list (Table#2)
+---------------+----------------+-----------------+
changelistid(PK)|lookahead_run_id|change_list_id
+---------------+----------------+-----------------+
38591-----------+15963-----------+34022
38590-----------+15963-----------+34021
38589-----------+15963-----------+34020
change_lists (Table#3)
+-------------+-----------+
change_list_id|changelist
+-------------+-----------+
34022-------- 1823900
34021-------- 1819483
34020-------- 1818572
错误: -
Error 1 Cannot implicitly convert type 'string' to 'System.Collections.Generic.List<string>'
答案 0 :(得分:0)
看一下类定义,changelists
被定义为List,现在看看查询,在这里你将cl.change_list.ToString()
分配给List Of string。并且这是相同的错误消息说,您正在尝试将字符串值分配给字符串列表。
<强>修正强>
如果您确定changelists
是列表的数据类型,请从查询中删除.ToString()
,然后使用.ToList()
。如果changelists
是字符串,则表示在属性定义中进行必要的更改。