I have a query that im trying to implement in LLBLGen:
SELECT DISTINCT ipcc.DIRECTORY_NUMBER_OR_PATTERN from TB_DIM_DIRECTORY_NUMBER ipcc
JOIN TB_DIM_DIRECTORY_NUMBER non ON non.DIRECTORY_NUMBER_URN = ipcc.DIRECTORY_NUMBER_URN AND non.DIRECTORY_NUMBER_OR_PATTERN = ipcc.DIRECTORY_NUMBER_OR_PATTERN
WHERE ipcc.IPCC_ENABLED <> non.IPCC_ENABLED OR ipcc.IPCC_ENABLED = 1
So far I have this C#:
IRelationPredicateBucket filter = new RelationPredicateBucket();
IEntityField2 ipccPat = DirectoryNumberFields.DirectoryNumberOrPattern.SetObjectAlias("ipcc");
IExpression expP = new Expression(ipccPat, ExOp.None, 1);
IEntityField2 nonPat = DirectoryNumberFields.DirectoryNumberOrPattern.SetObjectAlias("non");
IPredicateExpression patternFilter = new PredicateExpression();
patternFilter.Add(new FieldCompareExpressionPredicate(nonPat, null, ComparisonOperator.Equal, expP));
filter.Relations.Add(DirectoryNumberEntity.Relations.DirectoryNumberEntityUsingDirectoryNumberUrn, "non", "ipcc", JoinHint.Inner).CustomFilter = patternFilter;
IEntityField2 ipcc = DirectoryNumberFields.IpccEnabled.SetObjectAlias("ipcc");
IExpression exp = new Expression(ipcc, ExOp.None, 1);
IEntityField2 non = DirectoryNumberFields.IpccEnabled.SetObjectAlias("non");
filter.PredicateExpression.Add(new FieldCompareExpressionPredicate(non, null, ComparisonOperator.NotEqual, exp));
filter.PredicateExpression.AddWithOr(PredicateFactory.CompareValue(DirectoryNumberFieldIndex.IpccEnabled, ComparisonOperator.Equal, Boxed.True, "ipcc"));
this.Adapter.FetchEntityCollection(directoryNumbers, filter);
The problem is that the SQL generated isnt valid:
exec sp_executesql N'
SELECT DISTINCT [dbo].[TB_DIM_DIRECTORY_NUMBER].[DIRECTORY_NUMBER_URN] AS [DirectoryNumberUrn],
[dbo].[TB_DIM_DIRECTORY_NUMBER].[DIRECTORY_NUMBER_OR_PATTERN] AS [DirectoryNumberOrPattern],
[dbo].[TB_DIM_DIRECTORY_NUMBER].[IPCC_ENABLED] AS [IpccEnabled],
[dbo].[TB_DIM_DIRECTORY_NUMBER].[ROUTE_PARTITION_URN] AS [RoutePartitionUrn],
[dbo].[TB_DIM_DIRECTORY_NUMBER].[msrepl_tran_version] AS [MsreplTranVersion]
FROM ( [dbo].[TB_DIM_DIRECTORY_NUMBER] [LPA_i2]
INNER JOIN [dbo].[TB_DIM_DIRECTORY_NUMBER] [LPA_n1] ON [LPA_i2].[DIRECTORY_NUMBER_URN]=[LPA_n1].[DIRECTORY_NUMBER_URN]
AND ( [LPA_n1].[DIRECTORY_NUMBER_OR_PATTERN] = [LPA_i2].[DIRECTORY_NUMBER_OR_PATTERN]))
WHERE ( [LPA_n1].[IPCC_ENABLED] <> [LPA_i2].[IPCC_ENABLED] OR [LPA_i2].[IPCC_ENABLED] = @IpccEnabled1)',
N'@IpccEnabled1 bit', @IpccEnabled1 = 1
As you can see the sql has the wrong column alias in the select, e.g. [dbo].[TB_DIM_DIRECTORY_NUMBER] when i would like it to be [LPA_i2]
Can you help?
BTW DirectoryNumberEntity.Relations.DirectoryNumberEntityUsingDirectoryNumberUrn relation is a custom relation added using the IDE.