Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to convert the string value to date time

Class

public class demoDate
{
    public DateTime DueDate;
    public int OrderReportID;

    public DateTime _DueDate 
    { 
        get { return DueDate; } 
        set { DueDate = value; } 
    }

    public int _OrderReportID 
    { 
        get { return OrderReportID; } 
        set { OrderReportID = value;} 
    }
}

Query

var DateQuery = (from o in db.Order_Reports
                 select new demoDate {
                    DueDate = System.DateTime.Parse(o.ReportDueDateTime), 
                    OrderReportID = o.OrderReportID
                 }).ToList();

This coding shows following error

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
208 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you need convert it with SQL you can try use SqlFunctions.DateAdd and just add zero interval.

var DateQuery = db.Order_Reports.Select(o => new demoDate {
    DueDate = SqlFunctions.DateAdd("day", 0, o.ReportDueDateTime), 
    OrderReportID = o.OrderReportID
 });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...