I want to improve my code. Is it safe to rewrite the first example to the second?
IQueryable<PDF> pdfList = (from pdfobj in pdfDataContext.PDFs where pdfobj.Id == pdfId select pdfobj); if (pdfList.Count() > 0) { PDF pdfOldWay = pdfList.FirstOrDefault(); pdfOldWay.
-
PDF pdfNewWay = (from pdfobj in pdfDataContext.PDFs where pdfobj.Id == pdfId select pdfobj).SingleOrDefault(); if (pdfNewWay != null) {
-
EDIT:
Sorry for what you did not understand. My problem is to get the PDF object directly without using the list first. I donβt want to check to count more than 0, and because it just doesnβt look good.
source share