本文整理汇总了C#中DbExpression.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# DbExpression.ToArray方法的具体用法?C# DbExpression.ToArray怎么用?C# DbExpression.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbExpression
的用法示例。
在下文中一共展示了DbExpression.ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMockDbFunctionExpression
private static Mock<DbFunctionExpression> CreateMockDbFunctionExpression(
string functionName,
PrimitiveTypeKind returnType,
object argumentValue = null,
params string[] additionalArguments)
{
additionalArguments = additionalArguments ?? new string[0];
var mockEdmType = new Mock<PrimitiveType>();
mockEdmType.Setup(m => m.BuiltInTypeKind).Returns(BuiltInTypeKind.PrimitiveType);
mockEdmType.Setup(m => m.PrimitiveTypeKind).Returns(returnType);
var mockTypeUsage = new Mock<TypeUsage>();
mockTypeUsage.Setup(m => m.EdmType).Returns(mockEdmType.Object);
var mockArgument = new Mock<DbConstantExpression>();
mockArgument.Setup(m => m.ResultType).Returns(mockTypeUsage.Object);
mockArgument.Setup(m => m.Value).Returns(argumentValue);
var arguments = new DbExpression[] { mockArgument.Object }.Concat(
additionalArguments.Select(
a =>
{
var mockSqlWriter = new Mock<ISqlFragment>();
mockSqlWriter.Setup(m => m.WriteSql(It.IsAny<SqlWriter>(), It.IsAny<SqlGenerator>()))
.Callback((SqlWriter writer, SqlGenerator generator) => writer.Write(a));
var mockAdditionalArgument = new Mock<DbConstantExpression>();
mockAdditionalArgument.Setup(m => m.ResultType).Returns(mockTypeUsage.Object);
mockAdditionalArgument.Setup(m => m.Value).Returns("Value");
mockAdditionalArgument.Setup(m => m.Accept(It.IsAny<DbExpressionVisitor<ISqlFragment>>()))
.Returns(mockSqlWriter.Object);
return mockAdditionalArgument.Object;
}));
var mockExpression = new Mock<DbFunctionExpression>();
mockExpression.Setup(m => m.Function).Returns(CreateMockEdmFunction(functionName).Object);
mockExpression.Setup(m => m.Arguments).Returns(arguments.ToArray());
return mockExpression;
}