private DbExpression CreateEqualsExpression(
DbExpression left, DbExpression right, EqualsPattern pattern, Type leftClrType, Type rightClrType)
{
VerifyTypeSupportedForComparison(leftClrType, left.ResultType, null, false);
VerifyTypeSupportedForComparison(rightClrType, right.ResultType, null, false);
//For Ref Type comparison, check whether they refer to compatible Entity Types.
var leftType = left.ResultType;
var rightType = right.ResultType;
if (leftType.EdmType.BuiltInTypeKind == BuiltInTypeKind.RefType
&& rightType.EdmType.BuiltInTypeKind == BuiltInTypeKind.RefType)
{
TypeUsage commonType;
if (!TypeSemantics.TryGetCommonType(leftType, rightType, out commonType))
{
var leftRefType = left.ResultType.EdmType as RefType;
var rightRefType = right.ResultType.EdmType as RefType;
throw new NotSupportedException(
Strings.ELinq_UnsupportedRefComparison(leftRefType.ElementType.FullName, rightRefType.ElementType.FullName));
}
}
return RecursivelyRewriteEqualsExpression(left, right, pattern);
}