private static bool CanOmitCast(TypeUsage fromType, TypeUsage toType, bool preserveCastForDateTime)
{
var isPrimitiveType = TypeSemantics.IsPrimitiveType(fromType);
//SQLBUDT #573573: This is to allow for a workaround on Katmai via explicit casting by the user.
// The issue is that SqlServer's type Date maps to Edm.DateTime, same as SqlServer's DateTime and SmallDateTime.
// However the conversion is not possible for all values of Date.
//Note: we could also call here TypeSemantics.IsPrimitiveType(TypeUsage type, PrimitiveTypeKind primitiveTypeKind),
// but that checks again whether the type is primitive
if (isPrimitiveType
&& preserveCastForDateTime
&& ((PrimitiveType)fromType.EdmType).PrimitiveTypeKind == PrimitiveTypeKind.DateTime)
{
return false;
}
if (TypeUsageEquals(fromType, toType))
{
return true;
}
if (isPrimitiveType)
{
return fromType.EdmType.EdmEquals(toType.EdmType);
}
return TypeSemantics.IsSubTypeOf(fromType, toType);
}