0

Please check the method bellow. This method finds for matching date and count that matched data and returns that. Problem is I dont want to match date and time. I only want to match date and count them. Thats why i used ToShortDateString() to convert long date time to simple only date format. But problem is LINQ does not allow me to use ToShortDateString() on TransectionDate. Check debug picture bellow. How can i fix it?

public int ValueCalculator(DateTime date, string ItemID)
        {
            using (var ctx = new db_DemoEntities())
            {
                var simpleDate = date.ToShortDateString();
                int TotalSold = ctx.EbayUserTransactions.Where(x => x.TransactionDate.ToShortDateString() == simpleDate && x.ItemID == ItemID).Count();
                return TotalSold;
            }
        }

Debug pic

Gini Gal
  • 31
  • 3
  • @Stephen can u tell how can i implement duplicate answer on my method? – Gini Gal Apr 06 '18 at 12:37
  • Change `string ItemID` to `DateTime itemID` (do not try and compare dates as strings) and use either the answer by Sergey Berezovskiy or Damien_The_Unbeliever –  Apr 06 '18 at 12:40
  • https://ibb.co/bUUg4x i am getting same error even on this- int TotalSold = ctx.EbayUserTransactions.Where(x => EntityFunctions.TruncateTime(x.TransactionDate) == date.Date && x.ItemID == ItemID).Count(); see picture – Gini Gal Apr 06 '18 at 12:53

0 Answers0