【发布时间】:2022-10-07 14:08:04
【问题描述】:
在我的 asp.net MVC 应用程序中,查看模型我创建了一个属性类型string 来显示date。
但在模型中,该属性存储为DateTime,因此在我的查询中,我通过将日期时间转换为ToShortDateString 来分配它。
因为存储的值是与表中的日期时间。(example2022-10-06 11:32:48.917)
但在视图中,我只想显示日期。
运行此查询时出现此错误
LINQ to Entities does not recognize the method \'System.String ToShortDateString()\' method,
and this method cannot be translated into a store expression.\'
只想知道如何只将日期传递给这种查询的视图。
这是我当前的代码。
var TaskMain = (from t in db.TaskMain
join service in db.Services on t.Service_Id equals service.Id
join category in db.ServiceCategory on service.Service_Category_Id equals category.Id
join branch in db.Branch on t.Current_Branch_Id equals branch.Id
join emp in db.Employee on t.Task_Assigned_Emp_Id equals emp.Id
where t.Id == id
select new TaskDetails
{
Id = t.Id,
Note = t.Note,
Current_Step= t.Task_Step_Id,
Service_Category = category.Service_Category_Name,
Service_End_Date = t.Service_End_Date.ToShortDateString(),
Service_Price = t.Service_Price,
Service_Start_Date = t.CreatedDate.ToShortDateString(),
Task_Created_Branch = branch.BranchName,
Service_Name = service.Service_NameEng
}).ToList();
标签: c# asp.net asp.net-mvc entity-framework linq