I have some code:
(from AspNetUsers in db.AspNetUsers
join UserDetails in db.UserDetails on new { Id = Convert.ToInt32(AspNetUsers.UserDetailId) } equals new { I
You can use cast (i.e (int?)AspNetUsers.UserDetailId) instead of Convert and EF providers should implement it (is related to the provider). SQL Server EF provider probably converts it to CAST AS
You can't use a Convert.ToInt32
in linq to entities.
One way would be to do all this "in memory" (enumerate all).
But of course that's really bad for performance.
One other way, in your case, would be
First : do it the other way in the join (convert the int
in a string
: cause this way is doable in linq to entities).
=> new { Id = AspNetUsers.UserDetailId } equals new { Id = SqlFunctions.StringConvert((double)UserDetails.Id) }
Then : get only the data you need, enumerate and cast in linq to objects.
select new
{
AspNetUsersId = AspNetUsers.AspNetUsersId,
UsertId = UserDetails.UserID
}).ToList()
.Select (m => new {
m => m.AspNetUsersId,
UsertId = (int?)m.UsertId
});
Finally : the best way would be not to store int as varchar...