2014-07-25 3 views
0

내가 llblgen 작업을 다음과 같은 SQL을 얻으려고 ...LLBLgen 3.5 파생 테이블

SELECT *,(SELECT TOP (1) Id FROM Content.Grades WHERE Account = Authentication.Account.Id ORDER BY Grades.GradingDate DESC) AS CurrentGrade FROM Authentication.Account WHERE (SELECT TOP (1) Grade FROM Content.Grades WHERE Account = Authentication.Account.Id ORDER BY Grades.GradingDate DESC) = 5 


var dtFields = new ResultsetFields(1); 
      dtFields.DefineField(GradesFields.Id, 0); 
      var dtDefinition = new DerivedTableDefinition(
          dtFields, "c", new PredicateExpression(GradesFields.Grade == SelectedGrade.Value)); 

      // specify the relation which is a dynamic relation. 
      var relation = new DynamicRelation(dtDefinition, JoinHint.Inner, 
              EntityType.GradesEntity, "o", 
              (new EntityField2(AccountFields.Id.ToString(), "c", typeof(string)) == 
              GradesFields.Account.SetObjectAlias("o"))); 

      RelationBucket.Relations.Add(relation); 

가 나는 이것이 내가지고있어 쿼리를 시도으로 매번 맞게 얻기 위해 사투를 벌인거야 조회 현장의 오류 ...

답변

1

좋아, 여기에 내 자신의 문제를 해결했습니다.

파생 테이블을 사용할 때 모든 참조에 개체 별칭을 설정해야합니다. 여기에는 정렬 필드와 술어 필드가 포함됩니다.

  var dtFields = new ResultsetFields(2); 
      dtFields.DefineField(GradesFields.Account, 0); 
      dtFields.DefineField(GradesFields.Grade, 1); 
      var dtDefinition = new DerivedTableDefinition(
          dtFields, "c", null, null, 
          new SortExpression(GradesFields.GradingDate | SortOperator.Descending), null, 1, false); 

      // specify the relation which is a dynamic relation. 
      var relation = new DynamicRelation(dtDefinition, JoinHint.Inner, 
              EntityType.AccountEntity, "o", (AccountFields.Id.SetObjectAlias("o") == 
              GradesFields.Account.SetObjectAlias("c"))); 

      repositoryQuery.Relations.Add(relation); 
      repositoryQuery.PredicateExpression.Add(new EntityField2("Grade", "c", typeof(int)) == SelectedGrade.Value); 

AccountFields.Lastname.SetObjectAlias("o") | SortOperator.Ascending,