tags:

views:

77

answers:

0

Hi,

I am using Fluent NHib which generates the mappings bellow. I read this: http://www.progware.org/Blog/post/NHibernate-inverse3dtrue-and-cascade3dsave-update-demo.aspx but I still cannot figure it out. The only difference is that I am using GuidComb for PK.

Parent:

<bag access="nosetter.camelcase-underscore" cascade="save-update" inverse="true" name="CollectionWarehouse" table="Warehouse" mutable="true">
  <key foreign-key="Warehouse_Organization_FK">
    <column name="`Organization_Id`" />
  </key>
  <one-to-many class="Core.Model.OrganizationModel.Warehouse, Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>

And the other side:

<many-to-one class="Core.Model.OrganizationModel.Organization, Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" foreign-key="Org_FK" name="Org">
  <column name="`Organization_Id`" />
</many-to-one>

The code which saves the values.

IRepositoryWrapper<Organization> orgRepos = IoC.Resolve<IOrgRepository>();
        Organization org = new Organization();
        org.Name = "TestName";

        var wh1 =  new Warehouse();
        var wh2 = new Warehouse();

        org.AddWarehouse( wh1 );
        org.AddWarehouse( wh2 );
        orgRepos.Save( org );

Sorry for the long output:

NHibernate: INSERT INTO "Organization" (Version, CreatedBy, CreatedDateTime, UpdatedBy, UpdatedDateTime, "IdentityNumber", "IsOrg", "IsPricelistVatIncluded", "IsPrivate", "IsSimple", "Name", "Purpose", "VatNumber", "WebAddress", "Description", "IsActive", "OrganizationId") VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16);:p0 = 1 [Type: Int32 (0)], :p1 = NULL [Type: Guid (0)], :p2 = NULL [Type: DateTime (0)], :p3 = NULL [Type: Guid (0)], :p4 = NULL [Type: DateTime (0)], :p5 = 0 [Type: Int64 (0)], :p6 = False [Type: Boolean (0)], :p7 = False [Type: Boolean (0)], :p8 = False [Type: Boolean (0)], :p9 = False [Type: Boolean (0)], :p10 = 'TestName' [Type: String (0)], :p11 = NULL [Type: String (0)], :p12 = NULL [Type: String (0)], :p13 = NULL [Type: String (0)], :p14 = NULL [Type: String (0)], :p15 = False [Type: Boolean (0)], :p16 = a318ef1f-4787-445b-8c9b-9db800076ccf [Type: Guid (0)]

NHibernate: INSERT INTO "Warehouse" (Version, CreatedBy, CreatedDateTime, UpdatedBy, UpdatedDateTime, "IsPrivate", "IsSimple", "IsWarehouse", "Name", "Purpose", "Description", "IsActive", "Organization_Id", "Warehouse_Id", "WarehouseId") VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14);:p0 = 1 [Type: Int32 (0)], :p1 = NULL [Type: Guid (0)], :p2 = NULL [Type: DateTime (0)], :p3 = NULL [Type: Guid (0)], :p4 = NULL [Type: DateTime (0)], :p5 = False [Type: Boolean (0)], :p6 = False [Type: Boolean (0)], :p7 = False [Type: Boolean (0)], :p8 = NULL [Type: String (0)], :p9 = NULL [Type: String (0)], :p10 = NULL [Type: String (0)], :p11 = False [Type: Boolean (0)], :p12 = a318ef1f-4787-445b-8c9b-9db800076ccf [Type: Guid (0)], :p13 = NULL [Type: Guid (0)], :p14 = 28a09644-6864-41c4-9a5e-9db800076cde [Type: Guid (0)]

NHibernate: INSERT INTO "Warehouse" (Version, CreatedBy, CreatedDateTime, UpdatedBy, UpdatedDateTime, "IsPrivate", "IsSimple", "IsWarehouse", "Name", "Purpose", "Description", "IsActive", "Organization_Id", "Warehouse_Id", "WarehouseId") VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14);:p0 = 1 [Type: Int32 (0)], :p1 = NULL [Type: Guid (0)], :p2 = NULL [Type: DateTime (0)], :p3 = NULL [Type: Guid (0)], :p4 = NULL [Type: DateTime (0)], :p5 = False [Type: Boolean (0)], :p6 = False [Type: Boolean (0)], :p7 = False [Type: Boolean (0)], :p8 = NULL [Type: String (0)], :p9 = NULL [Type: String (0)], :p10 = NULL [Type: String (0)], :p11 = False [Type: Boolean (0)], :p12 = a318ef1f-4787-445b-8c9b-9db800076ccf [Type: Guid (0)], :p13 = NULL [Type: Guid (0)], :p14 = a00f93b9-0e6c-4bb5-9427-9db800076ce2 [Type: Guid (0)]

NHibernate: UPDATE "Organization" SET Version = :p0, CreatedBy = :p1, CreatedDateTime = :p2, UpdatedBy = :p3, UpdatedDateTime = :p4, "IdentityNumber" = :p5, "IsOrg" = :p6, "IsPricelistVatIncluded" = :p7, "IsPrivate" = :p8, "IsSimple" = :p9, "Name" = :p10, "Purpose" = :p11, "VatNumber" = :p12, "WebAddress" = :p13, "Description" = :p14, "IsActive" = :p15 WHERE "OrganizationId" = :p16 AND Version = :p17;:p0 = 2 [Type: Int32 (0)], :p1 = NULL [Type: Guid (0)], :p2 = NULL [Type: DateTime (0)], :p3 = NULL [Type: Guid (0)], :p4 = NULL [Type: DateTime (0)], :p5 = 0 [Type: Int64 (0)], :p6 = False [Type: Boolean (0)], :p7 = False [Type: Boolean (0)], :p8 = False [Type: Boolean (0)], :p9 = False [Type: Boolean (0)], :p10 = 'TestName' [Type: String (0)], :p11 = NULL [Type: String (0)], :p12 = NULL [Type: String (0)], :p13 = NULL [Type: String (0)], :p14 = NULL [Type: String (0)], :p15 = False [Type: Boolean (0)], :p16 = a318ef1f-4787-445b-8c9b-9db800076ccf [Type: Guid (0)], :p17 = 1 [Type: Int32 (0)]

NHibernate: UPDATE "Warehouse" SET Version = :p0, CreatedBy = :p1, CreatedDateTime = :p2, UpdatedBy = :p3, UpdatedDateTime = :p4, "IsPrivate" = :p5, "IsSimple" = :p6, "IsWarehouse" = :p7, "Name" = :p8, "Purpose" = :p9, "Description" = :p10, "IsActive" = :p11, "Organization_Id" = :p12, "Warehouse_Id" = :p13 WHERE "WarehouseId" = :p14 AND Version = :p15;:p0 = 2 [Type: Int32 (0)], :p1 = NULL [Type: Guid (0)], :p2 = NULL [Type: DateTime (0)], :p3 = NULL [Type: Guid (0)], :p4 = NULL [Type: DateTime (0)], :p5 = False [Type: Boolean (0)], :p6 = False [Type: Boolean (0)], :p7 = False [Type: Boolean (0)], :p8 = NULL [Type: String (0)], :p9 = NULL [Type: String (0)], :p10 = NULL [Type: String (0)], :p11 = False [Type: Boolean (0)], :p12 = a318ef1f-4787-445b-8c9b-9db800076ccf [Type: Guid (0)], :p13 = NULL [Type: Guid (0)], :p14 = 28a09644-6864-41c4-9a5e-9db800076cde [Type: Guid (0)], :p15 = 1 [Type: Int32 (0)]

NHibernate: UPDATE "Warehouse" SET Version = :p0, CreatedBy = :p1, CreatedDateTime = :p2, UpdatedBy = :p3, UpdatedDateTime = :p4, "IsPrivate" = :p5, "IsSimple" = :p6, "IsWarehouse" = :p7, "Name" = :p8, "Purpose" = :p9, "Description" = :p10, "IsActive" = :p11, "Organization_Id" = :p12, "Warehouse_Id" = :p13 WHERE "WarehouseId" = :p14 AND Version = :p15;:p0 = 2 [Type: Int32 (0)], :p1 = NULL [Type: Guid (0)], :p2 = NULL [Type: DateTime (0)], :p3 = NULL [Type: Guid (0)], :p4 = NULL [Type: DateTime (0)], :p5 = False [Type: Boolean (0)], :p6 = False [Type: Boolean (0)], :p7 = False [Type: Boolean (0)], :p8 = NULL [Type: String (0)], :p9 = NULL [Type: String (0)], :p10 = NULL [Type: String (0)], :p11 = False [Type: Boolean (0)], :p12 = a318ef1f-4787-445b-8c9b-9db800076ccf [Type: Guid (0)], :p13 = NULL [Type: Guid (0)], :p14 = a00f93b9-0e6c-4bb5-9427-9db800076ce2 [Type: Guid (0)], :p15 = 1 [Type: Int32 (0)]