Hi!
Given the lambda expression below where Province type contains a public property "byte CountryId" and Country type which contains a public property "byte Id".
Expression<Func<Province, bool>> exp = p => p.CountryId == country.Id;
The Expression is later used by NHibernate Linq provider and threw an exception. When I inspected the expression variable exp, I found out that both sides of the equality operator were converted to Int32.
{p => (Convert(p.CountryId) = Convert(value
(AddressToGo.Business.Default.AddressComponents+<>c__DisplayClass0).country.Id))}
I can't understand why the equality operator for two byte values need those values to be converted to Int32 beforehand. I have written the expression directly wihout letting the compiler do it for me. The following expression is converted by NHibernate Linq provider just fine.
ParameterExpression prm = Expression.Parameter(typeof(Province), "p");
Expression<Func<Province, bool>> exp =
Expression.Lambda<Func<Province, bool>>
(
Expression.Equal
(
Expression.MakeMemberAccess(prm, typeof(Province).GetProperty("CountryId")),
Expression.Constant(country.Id, typeof(byte))
),
prm
);
So, there must be a reason why the compiler outputs the expression with type conversion. Any ideas?