How can I convert datetime to data string?

Asked

Viewed 231 times

1

Follows 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 ?

inserir a descrição da imagem aqui

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(), but I get it this way in the view:

/Date(1491793200000)/

Some solution?

1 answer

3


Do it in the Select that will not have the message of error:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.