The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Return results through a FK where the record with the PK contains a specified value.

Last post 09-02-2008, 4:09 PM by Mike.Griffin. 6 replies.
Sort Posts: Previous Next
  •  08-25-2008, 6:06 AM 10900

    Return results through a FK where the record with the PK contains a specified value.

    Afternoon!

    I have an issue with 3 of my tables. These three tables are called Tbl_Docket (PK DocketId), Tbl_Installation (PK InstallationId FK DocketId), Tbl_Withdrawal ( PK WithdrawalId, FK DocketId).

    The docket table has a column called "Actioned" which is what I use on the PDA to determine whether or not to upload it to the server (if new/changes made).

    I need to get the three collections and serialize them using the Proxy Stub to send up to my webservice. So, I can generate the Tbl_Docket records using the simple query dockets.Query.Where(dockets.Query.Actioned.Equal("0"));

    How can I generate the collections of Tbl_Withdrawal and Tbl_Installation that correspond to those Dockets with the actioned value of 0? I.e. I don't want to send up all the installations and withdrawals everytime, I only want to send the collections that related to Dockets that are going to be uploaded.

    Thanks in advance.


    Current ES Projects:
    iVirtualDocket - Remote engineer tracking and job assignments
    HIS - Home insurance scripting system
  •  08-25-2008, 7:42 AM 10901 in reply to 10900

    Re: Return results through a FK where the record with the PK contains a specified value.

    Unless I'm misunderstanding wouldn't these be done via a simple join? (as shown on our home page) or is there more to it than that?
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-25-2008, 10:45 AM 10902 in reply to 10900

    Re: Return results through a FK where the record with the PK contains a specified value.

    Mike,

    since I am still learning the API, can you review and make sure that this is right? (This is good practice for me as well as maybe helping someone else)

     Dockets dockets = new Dockets();

    Installations installations = new Installations();

    Withdrawals withdrawals = new Withdrawals(); 

    dockets.Select(your docket columns here);

    installations.Select(your installation columns here);

    withdrawals.Select(your withdrawl columns here); 

    dockets.InnerJoin( installations).On(installations.DocketId == docket.DocketId);

    dockets.InnerJoin(withdrawals).On(withdrawals.DocketId == docket.DocketId);

    dockets.Where( dockets.Query.Actioned == "0");

     

     Yeehaw? Or no dice?

  •  08-25-2008, 11:37 AM 10903 in reply to 10902

    Re: Return results through a FK where the record with the PK contains a specified value.

    martinmizzell,

    In the main Page

    http://www.entityspaces.net/Portal/Default.aspx

    there is a example with join sintax.

     

  •  08-25-2008, 2:11 PM 10904 in reply to 10902

    Re: Return results through a FK where the record with the PK contains a specified value.

    I think you want to serialize each collection separately. You would use Joins to limit the rows included in the InstallationsCollection and WithdrawalsCollection. This should be fine for inserts/updates. I'm not sure how you are handling deletes. I cannot compile or test the code below, but it should be close.

    Code:
    DocketsCollection dockets = new DocketsCollection();
    dockets.Query.Where(dockets.Query.Actioned == "0");
    dockets.Query.Load();
    
    InstallationsQuery iq = new InstallationsQuery("i");
    DocketsQuery dq = new DocketsQuery("d");
    
    iq.Select(iq);
    iq.InnerJoin(dq).On(iq.DocketId == dq.DocketId);
    iq.Where(dq.Actioned == "0");
    
    InstallationsCollection installations = new InstallationsCollection();
    installations.Load(iq);
    
    WithdrawalsQuery wq = new WithdrawalsQuery("w");
    dq = new DocketsQuery("d");
    
    wq.Select(wq);
    wq.InnerJoin(dq).On(wq.DocketId == dq.DocketId);
    wq.Where(dq.Actioned == "0");
    
    WithdrawalsCollection withdrawals = new WithdrawalsCollection(); 
    withdrawals.Load(wq);

    David Neal Parsons
    www.entityspaces.net
  •  09-02-2008, 8:05 AM 11087 in reply to 10904

    Re: Return results through a FK where the record with the PK contains a specified value.

    How can I do the same thing, but through a link table?

    I.e. Measurements > LnkReportMeasurements > Reports, where Reports has an archived flag of "S"?

    I can get the Reports and LnkReportMeasurements, but I cannot seem to pull back measurements that relate to the reports with the required archived flag?

    Thanks.


    Current ES Projects:
    iVirtualDocket - Remote engineer tracking and job assignments
    HIS - Home insurance scripting system
  •  09-02-2008, 4:09 PM 11102 in reply to 11087

    Re: Return results through a FK where the record with the PK contains a specified value.

    We can do joins 'n' levels deep including subqueries. If you look at our home page there are 3 tables involved, basically, if you can write the select statement in SQL it looks the same in ES, but maybe I'm missing something. Our blog has some very complicated joins and stuff. Follow up if you need to.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML