How can I convert datetime to date string?

1

Follow the code:

var fullEntries = dbContext.tbl_EntryPoint
    .Join(
        dbContext.tbl_Title,
        combinedEntry => combinedEntry.entry.TID,
        title => title.TID,
        (combinedEntry, title) => new 
        {
            UID = combinedEntry.entry.OwnerUID,
            TID = combinedEntry.entry.TID,
            EID = combinedEntry.entryPoint.EID,
            Title = title.Title,
            DeadLine= combinedEntry.Date.ToShortDateString() // Aqui está o problema
        })
        .Where(fullEntry => fullEntry.UID == user.UID).ToList();

How can I convert datetime to date string?

  

I get the following error:

  

Additional information: LINQ to Entities does not recognize the method 'System.String ToShortDateString()' method, and this method cannot be translated into a store expression.

So I took ToShortDateString() , however I get that way in the view:

/Date(1491793200000)/

Any solution?

    
asked by anonymous 29.03.2017 / 02:05

1 answer

3

Do this in Select that will not have the error message :

var fullEntries = dbContext.tbl_EntryPoint
    .Join(
        dbContext.tbl_Title,
        combinedEntry => combinedEntry.entry.TID,
        title => title.TID,
        (combinedEntry, title) => new 
        {
            UID = combinedEntry.entry.OwnerUID,
            TID = combinedEntry.entry.TID,
            EID = combinedEntry.entryPoint.EID,
            Title = title.Title,
            DeadLine = combinedEntry.Date
        })
        .Where(fullEntry => fullEntry.UID == user.UID)
        .ToList()
        .Select(s => new {
            s.UID,
            s.TID,
            s.EID,
            s.Title,
            DeadLine = s.DeadLine.ToShortDateString()
        })
        .ToList();

References

29.03.2017 / 02:20