我写了一个自定义方法,如下所示:
DateTime GetGregorianDate(string date)
{
return new DateTime(int.Parse(date.Substring(0, 4)), int.Parse(date.Substring(5, 2)), int.Parse(date.Substring(8, 2)), new System.Globalization.PersianCalendar());
}
我想在 linq 查询中调用这个方法,如下所示:
dynamic GetPlayerListByTeamName(string teamCode, FutsalEntities myEntity)
{
var player = (from p in myEntity.Players
where p.TeamCode == teamCode && (GetGregorianDate(p.ContractDateTo) <= DateTime.Now) ? true : false
select new { p.MeliCode, p.BearthDate, p.ContractNumber, p.InsuranceNumber, p.ContractDate, p.Mobile });
return player;
}
这是调用代码的地方:
private void cmbTeams_SelectedIndexChanged(object sender, EventArgs e)
{
using (FutsalEntities myEntity = new FutsalEntities())
{
if (cmbTeams.SelectedIndex != -1 && myEntity.Players.Count() != 0)
{
dgPlayerList.DataSource = GetPlayerListByTeamName(cmbTeams.SelectedValue.ToString(), myEntity);
但是当我运行应用程序时出现此错误:
LINQ to Entities 无法识别方法 'System.DateTime GetGregorianDate(System.String)' 方法,并且此方法无法转换为存储表达式。
有没有办法在 linq 查询中调用这个方法?