public int FindMeasure(string measureDesc) { var query2 = from b in measureRepo.Measures where b.MeasureDesc == measureDesc orderby b.MeasureDesc select b.MeasureID; int result = query2.FirstOrDefault(); if (result == 0) { measureRepo.SaveMeasure(new Measure { MeasureDesc = measureDesc }); var query3 = from b in measureRepo.Measures where b.MeasureDesc == measureDesc orderby b.MeasureDesc select b.MeasureID; result = query3.FirstOrDefault(); } return(result); }