本文整理汇总了C#中DbFunctionExpression类的典型用法代码示例。如果您正苦于以下问题:C# DbFunctionExpression类的具体用法?C# DbFunctionExpression怎么用?C# DbFunctionExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbFunctionExpression类属于命名空间,在下文中一共展示了DbFunctionExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override Expression Visit(DbFunctionExpression expression)
{
Expression[] arguments = new Expression[expression.Arguments.Count];
for (int i = 0; i < expression.Arguments.Count; i++)
{
arguments[i] = this.Visit(expression.Arguments[i]);
}
return this.functionMapper.CreateMethodCall(expression.Function, arguments);
}
示例2: Generate
public SqlFragment Generate(DbFunctionExpression e, SqlGenerator caller)
{
callingGenerator = caller;
if (bitwiseFunctions.ContainsKey(e.Function.Name))
return BitwiseFunction(e);
else if (dateFunctions.ContainsKey(e.Function.Name))
return GenericFunction(dateFunctions, e);
else if (stringFunctions.ContainsKey(e.Function.Name))
return GenericFunction(stringFunctions, e);
else if (mathFunctions.ContainsKey(e.Function.Name))
return GenericFunction(mathFunctions, e);
return null;
}
示例3: WriteInstanceFunctionCall
private static ISqlFragment WriteInstanceFunctionCall(
SqlGenerator sqlgen, string functionName, DbFunctionExpression functionExpression, bool isPropertyAccess)
{
return WriteInstanceFunctionCall(sqlgen, functionName, functionExpression, isPropertyAccess, null);
}
示例4: HandleSpatialCanonicalFunction
private static ISqlFragment HandleSpatialCanonicalFunction(
SqlGenerator sqlgen, DbFunctionExpression functionExpression, PrimitiveTypeKind spatialTypeKind)
{
Debug.Assert(
spatialTypeKind == PrimitiveTypeKind.Geography || spatialTypeKind == PrimitiveTypeKind.Geometry,
"Spatial function does not refer to a valid spatial primitive type kind?");
if (spatialTypeKind == PrimitiveTypeKind.Geography)
{
return HandleSpatialCanonicalFunction(
sqlgen, functionExpression, _geographyFunctionNameToStaticMethodHandlerDictionary,
_geographyFunctionNameToInstancePropertyNameDictionary, _geographyRenamedInstanceMethodFunctionDictionary);
}
else
{
return HandleSpatialCanonicalFunction(
sqlgen, functionExpression, _geometryFunctionNameToStaticMethodHandlerDictionary,
_geometryFunctionNameToInstancePropertyNameDictionary, _geometryRenamedInstanceMethodFunctionDictionary);
}
}
示例5: HandleSpecialCanonicalFunction
/// <summary>
/// Handler for special canonical functions
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private static ISqlFragment HandleSpecialCanonicalFunction(SqlGenerator sqlgen, DbFunctionExpression e)
{
return HandleSpecialFunction(_canonicalFunctionHandlers, sqlgen, e);
}
示例6: HandleFunctionArgumentsDefault
/// <summary>
/// Default handling on function arguments.
/// Appends the list of arguments to the given result
/// If the function is niladic it does not append anything,
/// otherwise it appends (arg1, arg2, .., argn)
/// </summary>
/// <param name="e"></param>
/// <param name="result"></param>
private static void HandleFunctionArgumentsDefault(SqlGenerator sqlgen, DbFunctionExpression e, SqlBuilder result)
{
var isNiladicFunction = e.Function.NiladicFunctionAttribute;
Debug.Assert(
!(isNiladicFunction && (0 < e.Arguments.Count)),
"function attributed as NiladicFunction='true' in the provider manifest cannot have arguments");
if (isNiladicFunction && e.Arguments.Count > 0)
{
throw new MetadataException(Strings.SqlGen_NiladicFunctionsCannotHaveParameters);
}
if (!isNiladicFunction)
{
WriteFunctionArguments(sqlgen, e.Arguments, result);
}
}
示例7: HandleFunctionDefaultGivenName
/// <summary>
/// Default handling for functions with a given name.
/// Translates them to FunctionName(arg1, arg2, ..., argn)
/// </summary>
/// <param name="e"></param>
/// <param name="functionName"></param>
/// <returns></returns>
private static ISqlFragment HandleFunctionDefaultGivenName(SqlGenerator sqlgen, DbFunctionExpression e, string functionName)
{
// NOTE: The order of checks is important in case of CHARINDEX.
if (CastReturnTypeToInt64(e))
{
return HandleFunctionDefaultCastReturnValue(sqlgen, e, functionName, "bigint");
}
else if (CastReturnTypeToInt32(sqlgen, e))
{
return HandleFunctionDefaultCastReturnValue(sqlgen, e, functionName, "int");
}
else if (CastReturnTypeToInt16(e))
{
return HandleFunctionDefaultCastReturnValue(sqlgen, e, functionName, "smallint");
}
else if (CastReturnTypeToSingle(e))
{
return HandleFunctionDefaultCastReturnValue(sqlgen, e, functionName, "real");
}
else
{
return HandleFunctionDefaultCastReturnValue(sqlgen, e, functionName, null);
}
}
示例8: IsSpatialCanonicalFunction
/// <summary>
/// Determines whether the given function is a canonical function the translates
/// to a spatial (geography/geometry) property access or method call.
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private static bool IsSpatialCanonicalFunction(DbFunctionExpression e, out PrimitiveTypeKind spatialTypeKind)
{
if (e.Function.IsCanonicalFunction())
{
if (e.ResultType.IsSpatialType(out spatialTypeKind))
{
return true;
}
foreach (var functionParameter in e.Function.Parameters)
{
if (functionParameter.TypeUsage.IsSpatialType(out spatialTypeKind))
{
return true;
}
}
}
spatialTypeKind = default(PrimitiveTypeKind);
return false;
}
示例9: CastReturnTypeToInt32
/// <summary>
/// determines if the function requires the return type be enforeced by use of a cast expression
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
internal static bool CastReturnTypeToInt32(SqlGenerator sqlgen, DbFunctionExpression e)
{
if (!_functionRequiresReturnTypeCastToInt32.Contains(e.Function.FullName))
{
return false;
}
return e.Arguments.Select(t => sqlgen.StoreItemCollection.StoreProviderManifest.GetStoreType(t.ResultType))
.Any(storeType => _maxTypeNames.Contains(storeType.EdmType.Name));
}
示例10: WrapPredicate
/// <summary>
/// Turns a predicate into a statement returning a bit
/// PREDICATE => CASE WHEN (PREDICATE) THEN CAST(1 AS BIT) WHEN (NOT (PREDICATE)) CAST (O AS BIT) END
/// The predicate is produced by the given predicateTranslator.
/// </summary>
/// <param name="predicateTranslator"></param>
/// <param name="e"></param>
/// <returns></returns>
private static ISqlFragment WrapPredicate(
Func<SqlGenerator, IList<DbExpression>, SqlBuilder, SqlBuilder> predicateTranslator, SqlGenerator sqlgen, DbFunctionExpression e)
{
var result = new SqlBuilder();
result.Append("CASE WHEN (");
predicateTranslator(sqlgen, e.Arguments, result);
result.Append(") THEN cast(1 as bit) WHEN ( NOT (");
predicateTranslator(sqlgen, e.Arguments, result);
result.Append(")) THEN cast(0 as bit) END");
return result;
}
示例11: HandleCanonicalFunctionEndsWith
/// <summary>
/// Handler for EndsWith. Wraps the normal translation with a case statement
/// </summary>
/// <param name="sqlgen"></param>
/// <param name="e"></param>
/// <returns></returns>
private static ISqlFragment HandleCanonicalFunctionEndsWith(SqlGenerator sqlgen, DbFunctionExpression e)
{
return WrapPredicate(HandleCanonicalFunctionEndsWith, sqlgen, e);
}
示例12: HandleCanonicalFunctionToUpper
/// <summary>
/// Function rename ToUpper -> UPPER
/// </summary>
/// <param name="sqlgen"></param>
/// <param name="e"></param>
/// <returns></returns>
private static ISqlFragment HandleCanonicalFunctionToUpper(SqlGenerator sqlgen, DbFunctionExpression e)
{
return HandleFunctionDefaultGivenName(sqlgen, e, "UPPER");
}
示例13: HandleCanonicalFunctionTrim
/// <summary>
/// TRIM(string) -> LTRIM(RTRIM(string))
/// </summary>
/// <param name="sqlgen"></param>
/// <param name="e"></param>
/// <returns></returns>
private static ISqlFragment HandleCanonicalFunctionTrim(SqlGenerator sqlgen, DbFunctionExpression e)
{
var result = new SqlBuilder();
result.Append("LTRIM(RTRIM(");
Debug.Assert(e.Arguments.Count == 1, "Trim should have one argument");
result.Append(e.Arguments[0].Accept(sqlgen));
result.Append("))");
return result;
}
示例14: HandleCanonicalFunctionAbs
/// <summary>
/// Handle the canonical function Abs().
/// </summary>
/// <param name="sqlgen"></param>
/// <param name="e"></param>
/// <returns></returns>
private static ISqlFragment HandleCanonicalFunctionAbs(SqlGenerator sqlgen, DbFunctionExpression e)
{
// Convert the call to Abs(Byte) to a no-op, since Byte is an unsigned type.
if (e.Arguments[0].ResultType.IsPrimitiveType(PrimitiveTypeKind.Byte))
{
var result = new SqlBuilder();
result.Append(e.Arguments[0].Accept(sqlgen));
return result;
}
else
{
return HandleFunctionDefault(sqlgen, e);
}
}
示例15: HandleCanonicalFunctionRoundOrTruncate
/// <summary>
/// Common handler for the canonical functions ROUND and TRUNCATE
/// </summary>
/// <param name="e"></param>
/// <param name="round"></param>
/// <returns></returns>
private static ISqlFragment HandleCanonicalFunctionRoundOrTruncate(SqlGenerator sqlgen, DbFunctionExpression e, bool round)
{
var result = new SqlBuilder();
// Do not add the cast for the Round() overload having two arguments.
// Round(Single,Int32) maps to Round(Double,Int32)due to implicit casting.
// We don't need to cast in that case, since the server returned type is same
// as the expected type. Cast is only required for the overload - Round(Single)
var requiresCastToSingle = false;
if (e.Arguments.Count == 1)
{
requiresCastToSingle = CastReturnTypeToSingle(e);
if (requiresCastToSingle)
{
result.Append(" CAST(");
}
}
result.Append("ROUND(");
Debug.Assert(e.Arguments.Count <= 2, "Round or truncate should have at most 2 arguments");
result.Append(e.Arguments[0].Accept(sqlgen));
result.Append(", ");
if (e.Arguments.Count > 1)
{
result.Append(e.Arguments[1].Accept(sqlgen));
}
else
{
result.Append("0");
}
if (!round)
{
result.Append(", 1");
}
result.Append(")");
if (requiresCastToSingle)
{
result.Append(" AS real)");
}
return result;
}