Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6653467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:16:22+00:00 2026-05-26T01:16:22+00:00

I am finding it very difficult to map a legacy database. Here is the

  • 0

I am finding it very difficult to map a legacy database.

Here is the scenario: A contractor applies for a new license. The license is queried and displayed. The contractor modifies any information that needs to be modified. And upon completion an application is saved to the database.

A license belongs to either a business or an owner, this is a one to any polymorphic association. The License itself holds a TableID and RecordID that are used to make the association.

Licenses have many Applications. There are several types of Applications in this System, so there is an “ApplicationCommon” table and an “LicenseApplication” table. This particular application is a for a license. The ApplicationCommon and The LicenseApplication share the same primary key. In other words the ApplicationCommon id is the same and the LicenseApplication id. So this is table inheritance (or so I think).

Because of the weird polymorphic association with the business, I have to query for the business data separately from the license (Or so I think, kind of new to nHibernate). Once I have the license and the business I try to make a new application, that is when the system fails.

Here is the exception that I get:

 "object references an unsaved transient instance - save the transient instance 
 before flushing. Type: LicenseApplication, Entity: LicenseApplication"

Here are the mappings:

    public LicenseApplicationMap()
    {
        Table("Applications_LicenseApplication");
        Id(x => x.ID).Column("intApplicationID").Not.Nullable();
        Map(x => x.TableID).Column("intTableID").Nullable();
        Map(x => x.RecordID).Column("intRecordID").Nullable();
        References(x => x.Type).Column("intLicenseTypeID").Not.Nullable();

        Map(x => x.InsuranceExpiresOn).Column("dtInsuranceExpiresOn");
        Map(x => x.WCInsuranceExpiresOn).Column("dtWCInsuranceExpiresOn");
        Map(x => x.Updated).Column("dtUpdated");
        Map(x => x.AuthorizedRepresentativeFirstName).Column("strAuthRepFirstName");
        Map(x => x.AuthorizedRepresentativeLastName).Column("strAuthRepLastName");
        Map(x => x.AuthorizedRepresentativeGreeting).Column("strAuthRepGreeting");

        HasOne(x => x.ApplicationCommon).ForeignKey("intApplicationID").Cascade.All();
        References(x => x.License).Column("intLicenseID");

        HasMany(x => x.Officers).KeyColumn("intApplicationID");
        HasMany(x => x.Designees).KeyColumn("intApplicationID");
    }

.

    public LicenseCommonMap()
    {
        Table("Licensing_LicenseCommon");
        Id(x => x.ID).Column("intLicenseID").Not.Nullable();
        Map(x => x.TableID).Column("intTableID").Nullable();
        Map(x => x.RecordID).Column("intRecordID").Nullable();
        Map(x => x.LicenseNumber).Column("strNumber");
        References(x => x.Type).Column("intLicenseTypeID").Not.Nullable();
        References(x => x.Status).Column("intLicenseStatusID").Not.Nullable();
        Map(x => x.StartsOn).Column("dtStartsOn");
        Map(x => x.EndsOn).Column("dtEndsOn");
        Map(x => x.CreatedOn).Column("dtCreatedOn");
        Map(x => x.RenewedOn).Column("dtRenewedOn");
        Map(x => x.InsuranceExpiresOn).Column("dtInsuranceExpiresOn");
        Map(x => x.WorkmansCompensationExpiresOn).Column("dtWCInsuranceExpiresOn");
        Map(x => x.LastUpdated).Column("dtLastUpdated");
        HasMany(x => x.Applications).KeyColumn("intLicenseID");
    }

.

    public ApplicationCommonMap()
    {
        Table("Applications_ApplicationCommon");
        Id(x => x.ID).Column("intApplicationID");
        References(x => x.Type).Column("intApplicationTypeID");
        References(x => x.Status).Column("intApplicationStatusID");
        References(x => x.LicenseApplication).Column("intApplicationID").Cascade.All();
    }

.

    public BusinessMap()
    {
        Table("Core_Business");
        Id(x => x.ID).Column("intBusinessID").GeneratedBy.Identity();

        Map(x => x.BusinessName).Column("strBusinessName").Not.Nullable();
        Map(x => x.PhoneNumber).Column("strPhoneNumber").Not.Nullable();
        Map(x => x.FaxNumber).Column("strFaxNumber").Not.Nullable();
        Map(x => x.EmailAddress).Column("strEmailAddress").Not.Nullable();
        Map(x => x.YearOrganized).Column("strYearOrganized").Not.Nullable();
        Map(x => x.LastUpdated).Column("dtLastUpdated").Not.Nullable();

        Map(x => x.PhysicalAddr1).Column("strPhysicalAddr1").Not.Nullable();
        Map(x => x.PhysicalAddr2).Column("strPhysicalAddr2").Nullable();
        Map(x => x.PhysicalCity).Column("strPhysicalCity").Not.Nullable();
        Map(x => x.PhysicalState).Column("strPhysicalState").Not.Nullable();
        Map(x => x.PhysicalCountry).Column("strPhysicalCountry").Not.Nullable();

        Map(x => x.PhysicalZip).Column("strPhysicalZip").Not.Nullable();

        Map(x => x.MailingAddr1).Column("strMailingAddr1").Not.Nullable();
        Map(x => x.MailingAddr2).Column("strMailingAddr2").Nullable();
        Map(x => x.MailingCity).Column("strMailingCity").Not.Nullable();
        Map(x => x.MailingState).Column("strMailingState").Not.Nullable();
        Map(x => x.MailingCountry).Column("strMailingCountry").Not.Nullable();

        Map(x => x.MailingZip).Column("strMailingZip").Not.Nullable();
    }

And finally, I am using .Net MVC, AutoMapper and S#rpArch, so here is my controller action, and my query. SaveLicense and SaveQuery bother perform the same logic, SaveOrUpdate, then Flush.

    [HttpPost]
    [Transaction]
    public ActionResult Edit(int id, LicenseViewModel applicationData)
    {
        // 1. Get the current license.
        var license = _licenseService.GetLicenseCommon(id);

        // 2. Make changes to license that where made during application process
        Mapper.Map<LicenseViewModel , LicenseCommon>(applicationData, license);
        var business = _licenseService.GetBusiness(license.RecordID);
        Mapper.Map<LicenseViewModel , Business>(applicationData, business);
        business.LastUpdated = DateTime.Now;

        // 3. Create a new application and add it to the license
        var application = new LicenseApplication();
        Mapper.Map<LicenseViewModel , LicenseApplication>(applicationData, application);
        application.Updated = DateTime.Now;
        application.InsuranceExpiresOn = DateTime.Parse(applicationData.GeneralLiabilityExpiration);
        application.WCInsuranceExpiresOn = DateTime.Parse(applicationData.WorkmansCompensationExpiration);
        application.TableID = 33;
        application.RecordID = license.RecordID;


        // 4. Save the license and it's applications to the database.
        license.Business = business;  //Don't think this works at all...
        license.Applications.Add(application);
        application.License = license;
        ///////////////// BOOM THIS IS WHERE IT BLOWS UP //////////////////////
        _licenseService.SaveLicense(license);
        _businessService.SaveBusiness(business);

        // 5. Convert the modified license and it's newly created application to an LicenseViewModel
        Mapper.Map<LicenseCommon, LicenseViewModel >(license, applicationData);

        // 6. return json or error message
        return Json(applicationData);
    }

Please tell me what is wrong with my mappings.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:16:23+00:00Added an answer on May 26, 2026 at 1:16 am

    HasMany(x => x.Applications).KeyColumn("intLicenseID"); is missing a .Cascade.All() so saving the license also saves changes to Applications.

    And .Inverse would be good too to tell NH that Application is responsible for the association.

    And also

    // class LicenseCommon
    public void Add(LicenseApplication application)
    {
        application.License = license;
        application.TableID = 33;
        application.RecordID = license.RecordID;
        Applications.Add(application);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am designing a website and I am finding it VERY difficult to
Finding windows FastCGI help is proving very difficult. Any help would be greatly apprciated.
I am finding it very difficult to grasp how the Views are loaded and
I'm finding it very difficult to survey the options for game programming in Ruby.
I'm finding it very difficult in discovering the correct method to configure my app
I'm finding it very difficult to develop with PyClips, because it appears to replace
I'm trying to generate a ms-word document with Yii. I'm finding very difficult to
I'm finding it very convenient to pass configuration and other data that is read
I am newbie and finding it very hard to grasp the syntax of Class
Today is my first day using ASP.NET MVC, and I'm finding it very intriguing.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.