我想执行这样的查询:
我的返回查询的类大致如下:
在这个查询中,我使用一个函数将我的日期时间转换为另一种格式进行展示,我使用这个函数来实现这个目的:
List<supervisorAnswerQuesttionPres> temp =
(from i in dbconnect.tblAnswerLists
where i.StudentNum == studentNumber
select new supervisorAnswerQuesttionPres
{
answerList = _resAnswerList,
questionList = _resQuestionist,
date = ConvertToPersianToShow(i.dateOfAnswer.Value.Date)
}).OrderBy(i => i.date).ToList();
我的返回查询的类大致如下:
public class supervisorAnswerQuesttionPres
{
public string date { set; get; }
public List<string> questionList { set; get; }
public List<string> answerList { set; get; }
}
在这个查询中,我使用一个函数将我的日期时间转换为另一种格式进行展示,我使用这个函数来实现这个目的:
public string ConvertToPersianToShow(DateTime? datetime)
{
string date;
DateTime dt;
if (!datetime.HasValue) return "";
dt = datetime.Value;
// dt = datetime;
string year = Convert.ToString(persian_date.GetYear(dt));
string month = Convert.ToString(persian_date.GetMonth(dt));
string day = Convert.ToString(persian_date.GetDayOfMonth(dt));
if (month.Length == 1)
{
month = "0" + Convert.ToString(persian_date.GetMonth(dt));
}
if (day.Length == 1)
{
day = "0" + Convert.ToString(persian_date.GetDayOfMonth(dt));
}
Convert.ToString(persian_date.GetMonth(dt)) + "/" +
+ dt.Minute + ")";
date = year + "/" + month + "/" + day;
return date;
}
这个函数只是将我的 DateTime 转换,但当我执行查询时,出现了以下错误:
Method 'System.String ConvertToPersianToShow(System.Nullable`1[System.DateTime])' has no supported translation to SQL.