I apologize for not looking more thoroughly at your code.
Your LotTable variable will essentially be a list of FirmWare values, because this part of the phrase:
returns just the FirmWare value of each item that matches your criteria (whether none, or one, or all of them match) - so, as others have mentioned, add a FirstOrDefault() to the end of that statement. At that point, your LotTable with be set to a single FirmWare value (basically, LotTable = x.FirmWare, where x is the first PartLot that matches your criteria). You could forego the Select and just take the first PartLot that matches your criteria this way:
var LotTable = Db.PartLot.FirstOrDefault(x=>
x.Company == Session.CompanyID &&
x.PartNum == PartBinRow.PartNum &&
x.LotNum == PartBinRow.LotNum);
Notice the use of FirstOrDefault instead of Where (you could still do .Where(criteria).FirstOrDefault() but it does the same thing)
And then check for null and do your work:
if (LotTable != null) {
decimal NewFirmware = decimal.Parse(LotTable.FirmWare) - NewRecord.Number01;
LotTable.FirmWare = NewFirmware.ToString();
}
Also, it looks like you’re attempting to update the value in the database. Once you Select anything from the database, you are working with the results of your query, and not the actual values in the database … so you can update them, but they will not save to the DB.
I have not been brave enough to directly update database values, so I have no experience to help with that part of your code.