if you asked me a year ago, i would have provided a similar answer to @jbrekke… but for reasons of database efficiency, I have learned that you dont want to retrieve the entire data record ESPECIALLY if you only want one value… you can also eliminate the “instance of an object” error another way.
Here is how I would retrieve just the partclass of the part (if you only want that one field. Note that I am using the double question ?? operator, which is a “null-coalescing” operator… basically it says: “If the returned value is null, then use this value instead”. That way you don’t get the “instance of an object” error.
Note also that we are simply defining the string partClass, and only returning that one value instead of the entire part record. This will add to your efficiency.
string partClass = Db.Part.Where(x =>
x.Company == ttLabor.Company &&
x.PartNum == jobAssembly.PartNum &&
x.AssemblySeq == jobAssembly.AssemblySeq ).Select( x=>x.ClassID)
.FirstOrDefault() ?? "@@@";
if (partClass != "@@@" {
//your part class is in the string variable partClass, and you can do something here
}