linq to sql to linq to object(date conversion)

时间:2013-10-21 10:46:40

标签: linq linq-to-sql linq-to-objects

有人可以将它转换成linq到sql并以某种方式删除吗?

 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();

1 个答案:

答案 0 :(得分: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();
相关问题