Implementation of SqlEntityExpression for entity references, i.e., entities that stem from a substatement. Entity references know the SqlEntityExpression inside the substatement (the referenced entity), and their columns are of type SqlColumnReferenceExpression.
Inheritance: SqlEntityExpression
    public void Initialize ()
    {
      var entityReferenceExpression = new SqlEntityReferenceExpression (typeof (Cook), "t", null, _entityDefinitionExpression);

      var expectedColumn = new SqlColumnReferenceExpression (typeof (string), "t", "Name", false, _entityDefinitionExpression);
      SqlExpressionTreeComparer.CheckAreEqualTrees (expectedColumn, entityReferenceExpression.Columns[0]);

      Assert.That (entityReferenceExpression.IdentityExpressionGenerator, Is.SameAs (_entityDefinitionExpression.IdentityExpressionGenerator));
    }
    public void CreateReference ()
    {
      var entityReferenceExpression = new SqlEntityReferenceExpression (typeof (Cook), "t", null, _entityDefinitionExpression);
      
      var exptectedResult = new SqlEntityReferenceExpression (typeof (Cook), "t", null, entityReferenceExpression);

      var result = entityReferenceExpression.CreateReference ("t", _entityDefinitionExpression.Type);

      SqlExpressionTreeComparer.CheckAreEqualTrees (exptectedResult, result);
    }
    public void GetColumn ()
    {
      var entityReferenceExpression = new SqlEntityReferenceExpression (typeof (Cook), "t", null, _entityDefinitionExpression);

      var result = entityReferenceExpression.GetColumn (typeof (string), "Test", false);

      var exprectedresult = new SqlColumnReferenceExpression (typeof (string), "t", "Test", false, _entityDefinitionExpression);

      SqlExpressionTreeComparer.CheckAreEqualTrees (exprectedresult, result);
    }
    public void Update ()
    {
      var entityReferenceExpression = new SqlEntityReferenceExpression (typeof (Cook), "t", null, _entityDefinitionExpression);

      var result = entityReferenceExpression.Update (typeof (Kitchen), "f", "testName");

      var exptectedResult = new SqlEntityReferenceExpression (typeof (Kitchen), "f", "testName", _entityDefinitionExpression);

      Assert.That (result.Name, Is.EqualTo ("testName"));
      SqlExpressionTreeComparer.CheckAreEqualTrees (exptectedResult, result);
    }
    public void ResolveMemberExpression_Association()
    {
      var referencedSqlExpression = new SqlEntityDefinitionExpression (typeof (DataContextTestClass.Customer), "c", null, e => e);

      var sqlEntityExpression = new SqlEntityReferenceExpression (typeof (DataContextTestClass.Order), "o", null, referencedSqlExpression);

      var memberInfo = typeof (DataContextTestClass.Order).GetProperty ("Customer");
      var result = _mappingResolver.ResolveMemberExpression (sqlEntityExpression, memberInfo);

      var expectedExpression = new SqlEntityRefMemberExpression (sqlEntityExpression, memberInfo);
      SqlExpressionTreeComparer.CheckAreEqualTrees (expectedExpression, result);
    }
    public void GenerateSql_VisitSqlEntityExpression_NamedEntity_ReferencingNamed ()
    {
      var referencedEntity = new SqlEntityDefinitionExpression (
          typeof (Cook),
          "c",
          "Cook",
          e => e,
          new[]
          {
              new SqlColumnDefinitionExpression (typeof (string), "t", "Name", false),
              new SqlColumnDefinitionExpression (typeof (string), "t", "City", false)
          });
      var entityExpression = new SqlEntityReferenceExpression (typeof (Cook), "c", "ref", referencedEntity);

      SqlGeneratingSelectExpressionVisitor.GenerateSql (entityExpression, _commandBuilder, _stageMock);

      Assert.That (_commandBuilder.GetCommandText (), Is.EqualTo ("[c].[Cook_Name] AS [ref_Name],[c].[Cook_City] AS [ref_City]"));
    }
    public void ToString_NamedReferencedEntity ()
    {
      var referencedEntity = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook), "e1");

      var entityReferenceExpression = new SqlEntityReferenceExpression (typeof (Cook), "q0", null, referencedEntity);

      var result = entityReferenceExpression.ToString ();

      Assert.That (result, Is.EqualTo ("[q0].[e1] (ENTITY-REF)"));
    }
    public void CreateReference ()
    {
      var columns = new[]
                   {
                       new SqlColumnDefinitionExpression (typeof (string), "c", "Name", false),
                       new SqlColumnDefinitionExpression (typeof (string), "c", "FirstName", false)
                   };

      var entityExpression = new SqlEntityDefinitionExpression (typeof (Cook), "c", null, e => e.GetColumn (typeof (int), "ID", true), columns);

      var result = entityExpression.CreateReference("c1", typeof(Cook));

      var expectedResult = new SqlEntityReferenceExpression (typeof (Cook), "c1", null, entityExpression);
      SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result);
    }