2013-10-21 4 views
0

어떤 사람이 그것을 linq으로 변환하여 어떻게 든 제거 할 수 있습니까?linq to linq to object (날짜 변환)

Func<string, DateTime?> tryToGetDate = value => 
     { 
      DateTime dateValue; 
      return DateTime.TryParse(value, out dateValue) 
       ? (DateTime?)dateValue 
       : null; 
     }; 

    var dates = (from bk in _context.BookDetails 
          join bkcategories in _context.BookCategories 
          on bk.BookId equals bkcategories.BookId 
          where bkcategories.CategoryId == Convert.ToInt64(categoryid) 
          let dateValue = tryToGetDate(bk.PublishedDate) 
          where dateValue != null && (DateTime)dateValue >= twomonths && (DateTime)dateValue <= today 
          orderby bk.PublishedDate descending, bk.BookId 
          select bk).Take(2).ToList(); 

답변

0
var dates = (from bk in _context.BookDetails 
          join bkcategories in _context.BookCategories 
          on bk.BookId equals bkcategories.BookId 
          where bkcategories.CategoryId == Convert.ToInt64(categoryid) 
          where SqlFunctions.IsDate(bk.PublishedDate.ToString())==1 && bk.PublishedDate >= twomonths && bk.PublishedDate <= today 
          orderby bk.PublishedDate descending, bk.BookId 
          select bk).Take(2).ToList();