【问题标题】:LLBLgen 3.5 Derived Tables QueryLLBLgen 3.5 派生表查询
【发布时间】:2014-09-17 09:15:12
【问题描述】:

我正在尝试让以下 SQL 与 llblgen 一起使用...

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);

我正在努力使它适合,因为每次我尝试查询时我都会在现场遇到错误......

【问题讨论】:

    标签: sql derived-table llblgen


    【解决方案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,
    

    【讨论】:

      猜你喜欢
      • 2015-10-16
      • 2016-01-05
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      相关资源
      最近更新 更多