public void VisitSqlEntityConstantExpression() { var expression = new SqlEntityConstantExpression(typeof(Cook), "test", new SqlLiteralExpression(12)); SqlPreparationFromExpressionVisitor.AnalyzeFromExpression( expression, _stageMock, _generator, _methodCallTransformerProvider, _context, _tableGenerator, _someOrderingExtractionPolicy); }
public void ResolveMemberAccess_OnSqlEntityConstantExpression() { var expression = new SqlEntityConstantExpression(typeof(Cook), new Cook(), Expression.Constant(14)); var memberInfo = typeof(Cook).GetProperty("FirstName"); MemberAccessResolver.ResolveMemberAccess(expression, memberInfo, _resolverMock, _stageMock, _mappingResolutionContext); }
public void VisitSqlEntityConstantExpression() { var entityConstant = new SqlEntityConstantExpression(typeof(Cook), new Cook(), Expression.Constant(0)); Assert.That( () => SqlGeneratingExpressionVisitor.GenerateSql(entityConstant, _commandBuilder, _stageMock), Throws.TypeOf <NotSupportedException> ().With.Message.EqualTo( "It is not supported to use a constant entity object in any other context than to compare it with another entity. " + "Expression: ENTITY(0) (of type: 'Remotion.Linq.SqlBackend.UnitTests.TestDomain.Cook').")); }
Expression IResolvedSqlExpressionVisitor.VisitSqlEntityConstantExpression(SqlEntityConstantExpression expression) { ArgumentUtility.CheckNotNull("expression", expression); var message = string.Format( "It is not supported to use a constant entity object in any other context than to compare it with another entity. " + "Expression: {0} (of type: '{1}').", FormattingExpressionTreeVisitor.Format(expression), expression.Type); throw new NotSupportedException(message); }
public void ResolveConstantExpression() { var customer = new DataContextTestClass.Customer { CustomerID = "abc" }; var constantExpr = Expression.Constant(customer); var result = _mappingResolver.ResolveConstantExpression(constantExpr); var expectedExpr = new SqlEntityConstantExpression(typeof(DataContextTestClass.Customer), customer, Expression.Constant(customer.CustomerID, typeof(string))); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpr, result); }
public void SetUp() { _stageMock = MockRepository.GenerateStrictMock <IMappingResolutionStage>(); _resolverMock = MockRepository.GenerateStrictMock <IMappingResolver>(); _context = new MappingResolutionContext(); _entityIdentityResolver = new EntityIdentityResolver(_stageMock, _resolverMock, _context); _entityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook), primaryKeyType: typeof(int)); _entityConstantExpression = new SqlEntityConstantExpression(typeof(Cook), new Cook(), Expression.Constant(0)); _entityRefMemberExpression = new SqlEntityRefMemberExpression( SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Kitchen)), typeof(Kitchen).GetProperty("Cook")); }
public Expression VisitSqlEntityConstant(SqlEntityConstantExpression expression) { ArgumentUtility.CheckNotNull("expression", expression); if (_currentContext == SqlExpressionContext.SingleValueRequired) { string message = string.Format( "Cannot use an entity constant ('{0}' of type '{1}') in a place where SQL requires a single value.", expression, expression.Type.Name); throw new NotSupportedException(message); } return(expression); // rely on Visit to apply correct semantics }
public void ResolveConstantExpression_EntityExpression() { Order order; using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { order = Order.NewObject(); } var constantExpression = Expression.Constant(order); var expression = _resolver.ResolveConstantExpression(constantExpression); var expected = new SqlEntityConstantExpression(constantExpression.Type, order, Expression.Constant(order.ID)); SqlExpressionTreeComparer.CheckAreEqualTrees(expected, expression); }
public void ResolveConstantExpression_WithMultiplePrimaryKeyMembers() { var entity = new DataContextTestClass.ClassWithCompoundPrimaryKey { Key1 = 1, Key2 = "two" }; var constantExpr = Expression.Constant(entity); var result = _mappingResolver.ResolveConstantExpression(constantExpr); var type = typeof(MappingResolver.CompoundIdentityTuple <int, string>); var expectedExpr = new SqlEntityConstantExpression(typeof(DataContextTestClass.ClassWithCompoundPrimaryKey), entity, Expression.New( type.GetConstructors().Single(), new[] { new NamedExpression("Item1", Expression.Constant(1)), new NamedExpression("Item2", Expression.Constant("two")) }, new[] { type.GetProperty("Item1"), type.GetProperty("Item2") })); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpr, result); }
public Expression VisitSqlEntityConstantExpression(SqlEntityConstantExpression expression) { throw new InvalidOperationException("SqlEntityConstantExpression is not valid at this point. (Must be wrapped within a NamedExpression.)"); }
public void SetUp() { _identityExpression = Expression.Constant(5); _expression = new SqlEntityConstantExpression(typeof(Cook), new object(), _identityExpression); }
Expression IResolvedSqlExpressionVisitor.VisitSqlEntityConstant(SqlEntityConstantExpression expression) { ArgumentUtility.CheckNotNull("expression", expression); // Not supported, required by IUnresolvedSqlExpressionVisitor. return(VisitExtension(expression)); }