Left JOIN, many to many

Posts   
 
    
hc
User
Posts: 3
Joined: 30-Jan-2010
# Posted on: 30-Jan-2010 20:59:17   

            RaceEntity r = new RaceEntity();

            RaceCollection races = new RaceCollection();

            IPredicateExpression filter = new PredicateExpression(RaceFields.Deleted == false);

            filter.AddWithAnd(RaceFields.Date >= raceDate);

            filter.AddWithAnd(RaceFields.Date <= raceDateTo);

            //if (Li2Principal.GetCurrentPrincipal().RaceAdmin)

            //{

            //  filter.AddWithAnd(HOW DO I GET THE RIGHT CRITERIA HERE == Li2Principal.GetCurrentPrincipal().AccountGuid);

            //}

            races.GetMulti(filter, 0, new SortExpression(RaceFields.Date | SortOperator.Descending));

            rptRaces.DataSource = races;

            rptRaces.DataBind();



Hi, I am new to this product, I have got some of the basics down pretty well. But, I can't figure out how to add this criteria to my "where" clause

My I have three tables Races, RaceAdmin, Account Race Admin has a Race.RaceGUID and an Account.AccountGUID relationship. So, what I want to do above is if the authenticated user is a RaceAdmin, I want to pull back only those races in the race table that the user is a RaceAdiin for. Any thoughts on how I can accomplish this? As this is such a common scenario, I would assume its simple, but I can't figure it out. Thanks for being willing to take a look!

hc
User
Posts: 3
Joined: 30-Jan-2010
# Posted on: 31-Jan-2010 01:59:48   

Either one of these SQL queries is what I am trying to achieve. Thanks

HC



SELECT r.* FROM Race r
INNER JOIN RaceAdmin ra ON ra.RaceGuid = r.Guid
WHERE ra.AccountGuid = '51a37af7-c5b8-4197-b117-ebaac9b1c54a'


SELECT r.* FROM Race r
WHERE r.Guid IN (SELECT RaceGuid FROM RaceAdmin WHERE AccountGuid='51a37af7-c5b8-4197-b117-ebaac9b1c54a')

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Jan-2010 19:27:59   

You should use Multi-entity filters:

RaceEntity r = new RaceEntity();
RaceCollection races = new RaceCollection();

IPredicateExpression filter = new PredicateExpression(RaceFields.Deleted == false);
filter.Add(RaceFields.Date >= raceDate);
filter.Add(RaceFields.Date <= raceDateTo);
filter.Add(RaceAdminFields.AccountGuid = '51a37af7-c5b8-4197-b117-ebaac9b1c54a');

RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(RaceEntity.Relations.RaceAdminEntityUsingGuid);

races.GetMulti(filter, 0, new SortExpression(RaceFields.Date | SortOperator.Descending),
     relationsToUse);
David Elizondo | LLBLGen Support Team
hc
User
Posts: 3
Joined: 30-Jan-2010
# Posted on: 01-Feb-2010 06:41:55   

thank you! I really appreciate the help!