public void DelNanny(string id) { IEnumerable <BE.Contract> contract = dimp.SearchContract(x => x.NannyID == id); if (contract.Count() != 0) { throw new Exception("canot delete this nanny you have to remove this contract :" + contract.Last().ContractCode); } dimp.DelNanny(dimp.SearchNany(x => x.NannyId == id).Last()); }