本文整理汇总了C#中DbExpression.CastTo方法的典型用法代码示例。如果您正苦于以下问题:C# DbExpression.CastTo方法的具体用法?C# DbExpression.CastTo怎么用?C# DbExpression.CastTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbExpression
的用法示例。
在下文中一共展示了DbExpression.CastTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCastExpression
// creates a CQT cast expression given the source and target CLR type
private DbExpression CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
{
// see if the source can be normalized as a set
var setSource = NormalizeSetSource(source);
if (!ReferenceEquals(source, setSource))
{
// if the resulting cast is a no-op (no either kind is supported
// for set sources), yield the source
if (null == GetCastTargetType(setSource.ResultType, toClrType, fromClrType, true))
{
return source;
}
}
// try to find the appropriate target target for the cast
var toType = GetCastTargetType(source.ResultType, toClrType, fromClrType, true);
if (null == toType)
{
// null indicates a no-op cast (from the perspective of the model)
return source;
}
return source.CastTo(toType);
}
示例2: AlignTypes
// Cast expression to align types between CQT and eLINQ
private DbExpression AlignTypes(DbExpression cqt, Type toClrType)
{
Type fromClrType = null; // not used in this code path
var toType = GetCastTargetType(cqt.ResultType, toClrType, fromClrType, false);
if (null != toType)
{
return cqt.CastTo(toType);
}
else
{
return cqt;
}
}