-2
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
}

That's how my code looks,

Manager = (res != null) ? res.Manager : string.empty 

is causing an error, there is no relation between the tblManager and tblSales table

python
  • 487
  • 1
  • 4
  • 7

1 Answers1

1

You can try to move the res != null decision out of the query.

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
}
Maarten
  • 22,527
  • 3
  • 47
  • 68