public InventorySales getinvSales(int mgrId, int SalesId)
{
Managerset res = null;
InventorySales invSales = (from x in sbdb.tblSalesn.where(i => i.salesId == Sid)
join y in sbdb.tblProds on x.salesid equals y.salesid into resSales
select new InventorySales()
{
ProductName = x.productname,
Location = (xyz!= null) ? xyz.location:string.empty,
Manager = (res != null) ? res.Manager : string.empty // error line
}).FirstOrDefault();
return invSales
}
这就是我的代码的外观,
Manager = (res != null) ? res.Manager : string.empty
导致错误,tblManager和tblSales表之间没有关系
答案 0 :(得分:1)
您可以尝试将res != null
决定移出查询。
public InventorySales getinvSales(int mgrId, int SalesId) {
var res = from ins in sbdb.tblManager
where(managerId == mgrID)
select new Managerset() {
Manager = ins.Manager
}).firstOrDefault();
InventorySales invSales = (from x in sbdb.tblSalesn.where(i=>i.salesId == Sid)
join y in sbdb.tblProds on x.salesid equals y.salesid into resSales
from xyz in result.DefaultIfEmpty()
select new InventorySales()
{
ProductName = x.productname,
Location = (xyz!= null) ? xyz.location:string.empty,
Manager = string.empty
}).FirstOrDefault();
if (invSales != null && res != null) {
invSales.Manager = res.Manager;
}
return invSales
}