(edit) Darn, too late
Connor wrote:
Hi Walaa,
Thank you for your response but that query will not produce the same result set.
I want to return all rows for "MurphyC"... PLUS all other alert stages that "MurphyC" has NOT subscribed to. Your query just shows the alert stages that MurphyC has subscribed to and does not include the remaining alert stages that MurphyC has not subscribed to.
this is the query:
SELECT
user_alerts.ua_user_lan_id,
user_alerts.ua_alert_stage_id,
Alert_Stages.as_alert_stage_id,
Alert_Stages.as_alert_stage
FROM
user_alerts
RIGHT JOIN
Alert_Stages ON ua.ua_alert_stage_id = Alert_Stages.as_alert_stage_id
AND
user_alerts.ua_user_lan_id = 'MurphyC'
you can also do:
SELECT
user_alerts.ua_user_lan_id,
user_alerts.ua_alert_stage_id,
Alert_Stages.as_alert_stage_id,
Alert_Stages.as_alert_stage
FROM
user_alerts
RIGHT JOIN
Alert_Stages ON ua.ua_alert_stage_id = Alert_Stages.as_alert_stage_id
WHERE
user_alerts.ua_user_lan_id = 'MurphyC'
OR
user_alerts.ua_user_lan_id IS NULL
LLBLGen Pro doesn't support derive tables (i.e the (SELECT *.. ) statements in a FROM clause), so you've to solve it differently.
Walaa's query would return the right values in the situation of an INNER join, the RIGHT join will give some false positives indeed. So when you use the CustomFilter feature to add the predicate for user_alerts.ua_user_lan_id = 'MurphyC' to the relation, you're set.
See for more information about CustomFilter:
Using the generated code - Adapter/Selfservicing - Advanced Filter usage -> custom filters for entity relations.
Let me better explain what I'm hoping to achieve.
Situation
There are 10 Alert stages.
Our user "MurphyC" has subscribed to 5 of these alerts and this has been recorded in the user alerts tables
Complication
The system needs a page to allow users to manage their alerts. We want to display a data grid using useralertscollection which will show all 10 alert stages and a checkbox. The checkbox will be checked if the user has this alert saved in the user_alerts table.
The reason I have gone with the right outer join is that it returns a sql result set of exactly what (i.e a row for all 10 alert stages) I want to bind to the data grid.
Question
How do I best achieve this in LLBLgen?? I have modifed my query (No major change - I just removed 2 columns as I can get the alertStagename by extending the useralertEntity).
SELECT ua.ua_user_lan_id,
ua.ua_alert_stage_id
FROM
(select * from user_alerts where ua_user_lan_id = 'MurphyC') as ua
RIGHT JOIN
Alert_Stages ON ua.ua_alert_stage_id = Alert_Stages.as_alert_stage_id
Answer
Convert the SQL query to work with LLBLGEN??? Can this be done via LLBLgen??
Yes it's possible, but not with the derived table statement (the '(select * from user_alerts where ua_user_lan_id = 'MurphyC') as ua'.
Hopefully you can help ???
My initial failed attempts
Dim userAlerts As New UserAlertsTypedListTypedList ' UserAlertsCollection()
Dim relationsToUse As New RelationCollection()
Dim selectFilter As IPredicateExpression = New PredicateExpression()
Dim relation As IEntityRelation = UserAlertsEntity.Relations.AlertStagesEntityUsingUsAlertStageId
relation.HintForJoins = JoinHint.Right
relation.CustomFilter.Add(selectFilter) ' = (UserAlertsFields.UaUserLanId = "MurphyC")
relationsToUse.Add(relation)
hmm, I'd do:
relation.CustomFilter = selectFilter ' = (UserAlertsFields.UaUserLanId = "MurphyC")
but that shouldn't matter much. What query does this piece of code produce? Could you check that with DQE tracing for us please?