SqlEntityConstantExpression holds the primary key for a constant entity.
Inheritance: Remotion.Linq.Clauses.Expressions.ExtensionExpression
    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 VisitSqlEntityConstantExpression (SqlEntityConstantExpression expression)
 {
   throw new InvalidOperationException ("SqlEntityConstantExpression is not valid at this point. (Must be wrapped within a NamedExpression.)");
 }
    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 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 ()
 {
   _identityExpression = Expression.Constant (5);
   _expression = new SqlEntityConstantExpression (typeof (Cook), new object(), _identityExpression);
 }
    public void VisitSqlEntityConstantExpression ()
    {
      var expression = new SqlEntityConstantExpression (typeof (Cook), "test", new SqlLiteralExpression (12));

      SqlPreparationFromExpressionVisitor.AnalyzeFromExpression (
          expression, _stageMock, _generator, _methodCallTransformerProvider, _context, null);
    }
    public Expression VisitSqlEntityConstantExpression (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.",
            FormattingExpressionTreeVisitor.Format (expression),
            expression.Type.Name);
        throw new NotSupportedException (message);
      }
      return expression; // rely on VisitExpression to apply correct semantics
    }
    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')."));
    }
    public void VisitSqlEntityConstantExpression_Throws ()
    {
      var entityConstantExpression = new SqlEntityConstantExpression (typeof (Cook), new Cook(), Expression.Constant (0));

      Assert.That (
          () => _singleValueRequiredVisitor.VisitSqlEntityConstantExpression (entityConstantExpression), 
          Throws.TypeOf<NotSupportedException>().With.Message.EqualTo (
            "Cannot use an entity constant ('ENTITY(0)' of type 'Cook') in a place where SQL requires a single value."));
    }
    public void VisitSqlEntityConstantExpression_ValueRequired ()
    {
      var expression = new SqlEntityConstantExpression (typeof (int), 5, Expression.Constant (1));
      var result = _valueRequiredVisitor.VisitSqlEntityConstantExpression (expression);

      Assert.That (result, Is.SameAs (expression));
    }
    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);
    }