0

我正在尝试让以下 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);

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

4

1 回答 1

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,
于 2014-07-25T15:15:23.387 回答