The EntitySpaces Community

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

Rebuilding the Hierarchical Model

Last post 04-18-2008, 6:10 PM by sburton. 4 replies.
Sort Posts: Previous Next
  •  04-17-2008, 6:41 AM 8928

    Rebuilding the Hierarchical Model

     

    MyGeneration:          v 1.3.0.3

    EntitySpaces:             v 2007.1.1210.0

     

    Basic Information:  I am using the lightweight Proxy Stub objects on the client and serializing them across web services to the server when they are de-serialized back into the heavy Proxy Stub objects, then back to the EntitySpaces objects to be saved.

     

    Problem:  Can not seem to re-build the hierarchical structure so it will save as one Hierarchical record.  Not sure of the correct associatings and AttachEntity that need to be made to do this.

    BASIC DATABASE STRUCTURE

    CREATE TABLE [dbo].[LoanApplication](

          [LoanApplication_Id] [int] IDENTITY(1,1) NOT NULL,

    }

    CREATE TABLE [dbo].[Applicant](

          [Applicant_Id] [int] IDENTITY(1,1) NOT NULL,

          [LoanApplication_Id] [int] NOT NULL,

    }

    CREATE TABLE [dbo].[ContactInfo](

          [ContactInfo_Id] [int] IDENTITY(1,1) NOT NULL,

    }

    CREATE TABLE [dbo].[ApplicantContactInfo](

          [Applicant_Id] [int] NOT NULL,

          [ContactInfo_Id] [int] NOT NULL,

    }

     

    Seeing:  The ContactInfo object is not saving in the structure.  It works if I save the ContactInfo first and then save the LoanApplication object outside of a transaction.

    WHAT I AM DOING CLIENT SIDE:

    LoanApplicationProxyStub loanApplication = new LoanApplicationProxyStub( );

    loanApplication.AppUserGUID = guid;

    loanApplication.MarketId = 17;

     

    ApplicantProxyStub applicant = new ApplicantProxyStub( );

    applicant.ApplicantTypeId = 1;

    applicant.FirstName = "Steve";

    applicant.LastName = "Burton";

    applicant.EmailAddress = "sburton@myemail.com";

     

    ContactInfoProxyStub contactInfo = new ContactInfoProxyStub( );

    contactInfo.ContactInfoTypeId = 1;

    contactInfo.AreaCode = "480";

    contactInfo.PhoneNumber = "5555555";

     

    // ws is the WebService Object:

     

    ws.CreateLoanApplication( Serializer<LoanApplicationProxyStub>( loanApplication ), Serializer<ApplicantProxyStub>( applicant ), Serializer<ContactInfoProxyStub>( contactInfo ) );

     

    WHAT I AM DOING SERVER SIDE:  (No Error Trapping Yet)

     

    /// <summary>

        /// Creates a new loan application.</summary>

        /// <param name="data">Serialized data from the Ryland.OnlineLoanApplication.LoanApplication Entity object.</param>

    [WebMethod]

    public int CreateLoanApplication( string loanApplicationData, string applicantData, string contactInfoData )

    {

    LoanApplication loanApplication = ( LoanApplication )Deserializer<LoanApplicationProxyStub>( loanApplicationData );

     

    Applicant applicant = ( Applicant )Deserializer<ApplicantProxyStub>( applicantData );

     

    ContactInfo contactInfo = ( ContactInfo )Deserializer<ContactInfoProxyStub>( contactInfoData );

     

     

    //contactInfo.Save( );  IF I DO THIS IT WORKS FINE.

     

                loanApplication.ApplicantCollectionByLoanApplicationId.AttachEntity( applicant );

                contactInfo.AssociateApplicantCollectionByApplicantContactInfo( applicant );

                applicant.AssociateContactInfoCollectionByApplicantContactInfo( contactInfo );

               

     

    loanApplication.Save( );          

     

    }

     

    REASONING:

     

    Code below casuses a failure if the ContactInfo object is not saved first (contactInfo.Save( ) ).

     

    applicant.AssociateContactInfoCollectionByApplicantContactInfo( contactInfo );

     

    QUESTION:

     

    What am I missing!  Do I have to build the ApplicateContactInfo with an AddNew() method.  After trying this there is not way to AddEntity for the ContactInfo...

     

    Please help Thanks.

  •  04-17-2008, 10:49 AM 8929 in reply to 8928

    Re: Rebuilding the Hierarchical Model

    This is how I am doing it that works.  But is this the right way?

    WEB SERVER CODE:

    Code:    

    [WebMethod]

    public int CreateLoanApplication( string loanApplicationData, string applicantData, string contactInfoData )

    {

    LoanApplication loanApplication = (LoanApplication)Deserializer<LoanApplicationProxyStub>( loanApplicationData );

    Applicant applicant = ( Applicant )Deserializer<ApplicantProxyStub>( applicantData );

    ContactInfo contactInfo = ( ContactInfo )Deserializer<ContactInfoProxyStub>( contactInfoData );

     

    using( esTransactionScope scope = new esTransactionScope( ) )

    {

    contactInfo.Save( );

     

    loanApplication.ApplicantCollectionByLoanApplicationId.AttachEntity( applicant );

    contactInfo.AssociateApplicantCollectionByApplicantContactInfo( applicant );

    applicant.AssociateContactInfoCollectionByApplicantContactInfo( contactInfo );

     

    loanApplication.Save( );

     

    scope.Complete( );

     

    return loanApplication.LoanApplicationId.Value;

    }

  •  04-18-2008, 5:47 AM 8935 in reply to 8929

    Re: Rebuilding the Hierarchical Model

    Let me review this but to be sure are you having a problem or is it working?

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  04-18-2008, 8:47 AM 8936 in reply to 8935

    Re: Rebuilding the Hierarchical Model

    It is working in my second post with the esTransactionScope.  I was unsure if the ContactInfo had to be saved first like I am doing it or if there was something else I needed to do.  I would think that on the Applicant.AssociateContactInfoCollectionByApplicantContactInfo( contactInfo ) would have updated/inserted the parent (ContactInfo) object like it is doing for the Many-to-Many (ApplicantContactInfo) table with this AssociateContactInfoCollectionByApplicantContactInfo method.

     If it doesn't it would be really cool if it did.  I just started using the Hierarchical part of ES.  Very Cool.Smile

  •  04-18-2008, 6:10 PM 8939 in reply to 8936

    Re: Rebuilding the Hierarchical Model

    How hard would it be to set the child foreign key when you call the AttachEntity( ).  For example:

    Code:
    loanApplication.ApplicantCollectionByLoanApplicationId.AttachEntity( applicant );
    contactInfo.AssociateApplicantCollectionByApplicantContactInfo( applicant );
    applicant.AssociateContactInfoCollectionByApplicantContactInfo( contactInfo );
    1.  The applicant object's foreign key should be set to the loanApplication primary key  (This would be really cool don't you think).
    2.  The contactInfo should be saved before the ManyToMany table row is created (even cooler).
    Food for thought: Stick out tongue.
View as RSS news feed in XML