I am using Entity Framework, and I have a line of code that is taking a var and translating it back to an iint for the database.
var record = context.enrollments.SingleOrDefault
(row => row.userId == int.Parse(UserID) && row.classId == int.Parse(ClassID));
Whenever I try to run it I receive rhis error. "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."
I have tried this as well
var record = context.enrollments.FirstOrDefault
(row => row.userId == Convert.ToInt32(UserID)
&& row.classId == Convert.ToInt32(ClassID));
and all I receive is this error message, "LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression
and finally I have tried this as well, which I know is unusual, but it has worked in the past for similar situations.
var record = context.enrollments.SingleOrDefault
(row => row.userId == CommonDLL.Sanitize<int>.ConvertType(UserID)
&& row.classId == CommonDLL.Sanitize<int>.ConvertType(ClassID));
In which I get this error. As you can see I have tried seveal different things and nothing is working, so any help would be great.
int.Parse
withConvert.ToInt32
to make it work. – DorianSystem.Convert.ToInt32
? I don't if this is specifically something that linq doesn't support. Just guessing here. – Superintendent