Search code examples
c#linq

Convert Date formate ("yyyy MM dd") into this Date formate("dd MMM yyyy")


LINQ to Entities does not recognize the System.String ToString(System.String) method, and this method cannot be translated into a store expression.

         List<ModelName> List = await (    
                           linq query write here   
                            select new ModelName  
                            {  
                             Column Name,   
                             BlacklistDate = VM.BlacklistDate.Tostring()      
                          }).ToListAsync();

Solution

  • Answer

      List<ModelName> List = await (    
                           linq query write here   
                            select new ModelName  
                            {  
                             Column Name,   
                             _BlacklistDate = VM.BlacklistDate.Value,     
                          }).ToListAsync(); 
                             List.ForEach(x => x.BlacklistDate = x._BlacklistDate.HasValue ? (x._BlacklistDate.Value).ToString("dd MMM yyyy") : "");  
                             return List;