这是代码:-
如何初始化数据
?
var data;
if (mode == "view")
{
data = (from a in ctx.tblEmployee
where a.CompanyId == companyId
join b in ctx.tblTO_ShiftSchedule on a.Id equals b.EmployeeId
where b.CompanyId == companyId
select new { a, b, c, d }).ToList();
}
else
{
data = (from a in ctx.tblEmployee
where a.CompanyId == companyId
select new { a, b, c, d }).ToList();
}
最佳答案
你不能初始化匿名类型,所以:
var data = mode == "view"
? (from a in ctx.tblEmployee
where a.CompanyId == companyId
join b in ctx.tblTO_ShiftSchedule on a.Id equals b.EmployeeId
where b.CompanyId == companyId
select new { a, b, c, d }).ToList()
: (from a in ctx.tblEmployee
where a.CompanyId == companyId
select new { a, b, c, d }).ToList();
关于c# - 必须初始化隐式类型的局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096293/