Record Not Found Error

We went down the road of using GetRows instead of using GetByID and handling the exception and taking an action like @slitzau suggested.

Thanks everyone!

You could also do the check directly using the “.Any” option in a Linq Query. The .Any is the quickest form of validation if you don’t actually need the data. It will return a simple true/false.

MessageBox.Show("UD110 exists is running");

string whereClauseUD110 = "Key1 = PMOPERATIONS";
string Key2 = tbTypeCode1.Value.ToString();
string Key3 = tbFreqCode1.Value.ToString();
string Key4 = tbEquipTypeID.Text;
string Key5 = string.Empty;
bool UD110exists = Ice.UD110.Any(x => x.Company == CurrentCompany && x.Key1 == Key1 && x.Key2 == Key2 && x.Key3 == Key3 && x.Key4 == Key4 && x.Key5 == Key5);
if (UD110exists) {
    MessageBox.Show("UD110 Exists");
} else {
    MessageBox.Show("UD110 does NOT Exist");
}
1 Like

There is also linq! Thanks @timshuwy . I’ve been obsessed with business objects and rest calls lately I didn’t even think of doing LINQ.

Not sure which one has better performance of less overhead, do you?

Linq will be quicker especially if you dont need the actual data extracted. For example, if you only need to validate that the part number entered exists, then you can do a simple linq query:

bool partExists = Db.Part.Any(x=>x.Company == CurrentCompany && x.PartNum == MyPartNum);

but if you need to have the description, then the line needs to be bigger… but if the description is all you need, then it is quicker in Linq than reading the entire record. You can also populate the description with something if the part is not found.

string partDesc =  Db.Part.Where(x=>x.Company == CurrentCompany && x.PartNum == MyPartNum).Select(x=>x.PartDescription).FirstOrDefault() ?? "Part Not Found";

Are both methods just as taxing on the system?