I'm trying to add a calculated field to this table and am getting an error because I need to alias my field expression. I just don't know how to go about doing that.
Dim fields As New ResultsetFields(8)
Dim myExpr As Expression
myExpr = New Expression(EntityFieldFactory.Create(MaPlansEquipmentRateFieldIndex.Volume), _
ExOp.Mul, EntityFieldFactory.Create(MaPlansEquipmentRateFieldIndex.Volume))
fields.DefineField(MaPlanFieldIndex.PlanId, 0, "PlanId", "Plan")
fields.DefineField(MaPlanFieldIndex.CycleId, 1, "CycleId", "Plan")
fields.DefineField(MaPlansEquipmentRateFieldIndex.MeterTypeId, 2, "MeterTypeId", "Rates")
fields.DefineField(MaMeterTypeFieldIndex.MeterType, 3, "MeterType", "MeterTypes")
fields.DefineField(MaPlansEquipmentRateFieldIndex.FlatFee, 4, "FlatFee", "Rates", AggregateFunction.Sum)
fields.DefineField(MaPlansEquipmentRateFieldIndex.Volume, 5, "Volume", "Rates", AggregateFunction.Sum)
fields.DefineField(MaPlansEquipmentRateFieldIndex.Base, 6, "Base", "Rates", AggregateFunction.Sum)
fields.DefineField(MaPlansEquipmentRateFieldIndex.Base, 7, "Test", "Rates", AggregateFunction.Sum)
fields(7).ExpressionToApply = myExpr
Dim relations As New RelationCollection()
relations.Add(MaPlanEntity.Relations.MaPlansEquipmentEntityUsingPlanId, "Plan", "Machine", JoinHint.None)
relations.Add(MaPlansEquipmentEntity.Relations.MaPlansEquipmentRateEntityUsingMaPlansEquipmentId, "Machine", "Rates", JoinHint.None)
relations.Add(MaPlansEquipmentRateEntity.Relations.MaMeterTypeEntityUsingMeterTypeId, "Rates", "MeterTypes", JoinHint.None)
Dim pe As IPredicateExpression = New PredicateExpression
pe.Add(PredicateFactory.CompareValue(MaPlanFieldIndex.PlanId, ComparisonOperator.Equal, planId, "Plan"))
Dim groupByClause As New GroupByCollection()
groupByClause.Add(fields(0))
groupByClause.Add(fields(1))
groupByClause.Add(fields(2))
groupByClause.Add(fields(3))
If I look at the SQL generated by this code I just need to include the alias for my calulated field and all will be good.
Is this possible?
Thanks in advance,
Warren