Mysql 为什么我的Linqued查询不起作用?

Mysql 为什么我的Linqued查询不起作用?,mysql,sql-server,linq,linq-to-sql,Mysql,Sql Server,Linq,Linq To Sql,我有一个运行良好的sql查询 select u.FirstName,u.LastName,case when ei.Gender=1 then 'Male' else 'Female' end as Gender,t.Name as 'Team Name',ei.MobileNumber,u.Phone as 'Alternative Number',u.EmailAddress,ei.AlternateEmailAddress,ei.GMail,ei.Skype,FORMAT(ei.D

我有一个运行良好的sql查询

    select u.FirstName,u.LastName,case when ei.Gender=1 then 'Male' else 'Female' end as Gender,t.Name as 'Team Name',ei.MobileNumber,u.Phone as 'Alternative Number',u.EmailAddress,ei.AlternateEmailAddress,ei.GMail,ei.Skype,FORMAT(ei.DateOfBirth,'dd-MMM-yyyy') AS BirthDay,ei.Address1,ei.Address2,ei.City,ei.[State],ei.Country,ei.ZipPostalCode,ei.Designation,ei.MasterLeaves
 from Employee e
inner join [user] u
on e.[User]=u.Id and IsDeleted!=1
inner join Team t 
on e.Team=t.Id
inner join EmployeeInformation ei
on e.AdditionalInformation=ei.Id
什么时候 我将相同的查询转换为linqued查询,即

    var EmpReport = (from Emp in db.Employees
                 join Usr in db.Users
                 on Emp.User equals Usr.Id
                 join Tm in db.Teams
                on Emp.Team equals Tm.Id
                 join Ei in db.EmployeeInformations
                 on Emp.AdditionalInformation equals Ei.Id
                 where Usr.IsDeleted  != true
                select new { Usr.FirstName, Usr.LastName, Gender = Ei.Gender == 1 ? "Male" : "Female", Team_Name = Tm.Name, Ei.MobileNumber, Alternative_Number = Usr.Phone, Email_Address = Usr.EmailAddress, Alternate_Email_Address = Ei.AlternateEmailAddress, Ei.GMail, Ei.Skype, Birthday = Ei.DateOfBirth.ToString("dd-MMM-yyyy"), Ei.Address1, Ei.Address2, Ei.State, Ei.Country, Ei.ZipPostalCode, Ei.Designation, Ei.MasterLeaves }).ToList();
它给了我这个错误

 LINQ to Entities does not recognize the method 
     'System.String ToString(System.String)' method, and this method cannot
      be translated into a store expression.
这个错误基本上是在这一部分造成的

Birthday = Ei.DateOfBirth.ToString("dd-MMM-yyyy").

我哪里出错了?

之所以出现错误,是因为
DateTime.ToString()
是一个.NET函数,不能直接转换为SQL。要么以原始格式返回
DateOfBirth
列,并在应用程序中显示结果后更改格式,要么使用Linq to Entities中的一些SQL函数,请参见以下回答:

您收到错误,因为
DateTime.ToString()
是一个.NET函数,不能直接转换为SQL。以原始格式返回
DateOfBirth
列,并在应用程序中显示结果后更改格式,或者使用Linq to Entities中提供的一些SQL函数,请参见以下答案: