我有以下控制器动作方法
public ActionResult BondCompletion(DateTime? ToDate)
{
List<BondCompletionViewModel> bondCompletionViewModel = new List <BondCompletionViewModel>();
if (ToDate != null)
{
bondCompletionViewModel = db.Employees.Select(y => new
{
y.JoiningDate ,
y.Commitments ,
y.EmployeeId ,
y.Name
})
.Where(x => x.JoiningDate.AddMonths(x.Commitments.Value).Month == ToDate.Value.Month)
.Select(z => new BondCompletionViewModel
{
EmployeeId = z.EmployeeId.Value,
EmployeeName = z.Name,
StartDate = z.JoiningDate,
EndDate = z.JoiningDate//.AddMonths(x.Commitments.Value)
}).ToList();
}
return View(bondCompletionViewModel);
}
Run Code Online (Sandbox Code Playgroud)
在上面的方法中,Commitments是nullable int,JoiningDate是datetime.当我运行此如果显示以下错误
" LINQ to Entities无法识别方法'System.DateTime AddMonths(Int32)'方法,并且此方法无法转换为存储表达式."
请指导我如何解决此错误.
我需要使用数据注释来验证所有印度手机号码。在我的模型中,我使用以下代码
[Required]
[Display(Name = "Mobile Number")]
[CustomRemote("IsMobileNoAvailable", "Employees",
ErrorMessage = "Mobile No already in use", AdditionalFields = "Id")]
[?]
public string ContactNumber { get; set; }
Run Code Online (Sandbox Code Playgroud)
但是我很困惑我需要写些什么来代替[?]吗?请建议我验证手机号码的最佳方法。