我正在尝试使用以下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);
我每次尝试查询时都会努力让这个变得合适我在场上会遇到错误......
答案 0 :(得分: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,