Skip to content

Instantly share code, notes, and snippets.

@ravensorb
Last active February 18, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravensorb/14193136002adbb3ec2fac07c026f921 to your computer and use it in GitHub Desktop.
Save ravensorb/14193136002adbb3ec2fac07c026f921 to your computer and use it in GitHub Desktop.
A working example of the issue working with Interfaces with NHibernate that results in a "dehydration" exception. This gist needs to nuget packages -- FluentNHibernate and Sqlite.
Creating Session Factory
INF: NHibernate 5.0.3 (assembly 5.0.0.0)
INF: hibernate-configuration section not found in application configuration file
INF: Bytecode provider name : lcg
INF: Using reflection optimizer
DBG: Mapping XML:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"><class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.ICataglog, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tblCatalog"><id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Id" /><generator class="assigned" /></id><property name="Name" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Name" /></property></class></hibernate-mapping>
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Mapping class: NHibernate.ConsoleTest.ICataglog -> tblCatalog
DBG: Mapped property: Id -> Id, type: Guid
DBG: Mapped property: Name -> Name, type: String
DBG: Mapping XML:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"><class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.IProduct, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tblProduct"><id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Id" /><generator class="assigned" /></id><property name="Name" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Name" /></property><property name="SKU" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="SKU" /></property><property name="MSRP" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="MSRP" /></property><many-to-one cascade="save-update" class="NHibernate.ConsoleTest.ICataglog, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Catalog"><column name="Catalog_id" /></many-to-one></class></hibernate-mapping>
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Mapping class: NHibernate.ConsoleTest.IProduct -> tblProduct
DBG: Mapped property: Id -> Id, type: Guid
DBG: Mapped property: Name -> Name, type: String
DBG: Mapped property: SKU -> SKU, type: String
DBG: Mapped property: MSRP -> MSRP, type: Decimal
DBG: Mapped property: Catalog -> Catalog_id, type: NHibernate.ConsoleTest.ICataglog
DBG: Mapping XML:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"><class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.IOrder, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tblOrder"><id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Id" /><generator class="assigned" /></id><bag cascade="all" name="Lines"><key><column name="Id" /></key><one-to-many class="NHibernate.ConsoleTest.IOrderLine, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /></bag><property name="CreatedOn" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="CreatedOn" /></property></class></hibernate-mapping>
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Mapping class: NHibernate.ConsoleTest.IOrder -> tblOrder
DBG: Mapped property: Id -> Id, type: Guid
DBG: Mapped property: Lines, type: System.Collections.Generic.ICollection`1[[NHibernate.ConsoleTest.IOrderLine, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](NHibernate.ConsoleTest.IOrder.Lines)
DBG: Mapped property: CreatedOn -> CreatedOn, type: DateTime
DBG: Mapping XML:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"><class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.IOrderLine, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tbOrderLine"><id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Id" /><generator class="assigned" /></id><property name="Qty" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Qty" /></property><property name="Price" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><column name="Price" /></property><many-to-one cascade="save-update" class="NHibernate.ConsoleTest.IProduct, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" foreign-key="productId" name="Product" property-ref="Id"><column name="Product_id" /></many-to-one></class></hibernate-mapping>
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Mapping class: NHibernate.ConsoleTest.IOrderLine -> tbOrderLine
DBG: Mapped property: Id -> Id, type: Guid
DBG: Mapped property: Qty -> Qty, type: Int32
DBG: Mapped property: Price -> Price, type: Decimal
DBG: Mapped property: Product -> Product_id, type: NHibernate.ConsoleTest.IProduct
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: checking mappings queue
INF: processing one-to-many association mappings
DBG: Second pass for collection: NHibernate.ConsoleTest.IOrder.Lines
INF: mapping collection: NHibernate.ConsoleTest.IOrder.Lines -> tbOrderLine
DBG: Mapped collection key: Id, one-to-many: NHibernate.ConsoleTest.IOrderLine
INF: processing one-to-one association property references
INF: processing foreign key constraints
DBG: resolving reference to class: NHibernate.ConsoleTest.ICataglog
DBG: resolving reference to class: NHibernate.ConsoleTest.IOrder
DBG: resolving reference to class: NHibernate.ConsoleTest.IProduct
INF: processing filters (second pass)
INF: checking mappings queue
INF: processing one-to-many association mappings
INF: processing one-to-one association property references
INF: processing foreign key constraints
DBG: resolving reference to class: NHibernate.ConsoleTest.ICataglog
DBG: resolving reference to class: NHibernate.ConsoleTest.IOrder
DBG: resolving reference to class: NHibernate.ConsoleTest.IProduct
INF: processing filters (second pass)
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Initializing connection provider: NHibernate.Connection.DriverConnectionProvider
INF: Configuring ConnectionProvider
DBG: Obtaining DbConnection from Driver
DBG:
PRAGMA foreign_keys = OFF
DBG:
drop table if exists tblCatalog
DBG:
drop table if exists tblProduct
DBG:
drop table if exists tblOrder
DBG:
drop table if exists tbOrderLine
DBG:
PRAGMA foreign_keys = ON
DBG:
create table tblCatalog (
Id UNIQUEIDENTIFIER not null,
Name TEXT,
primary key (Id)
)
DBG:
create table tblProduct (
Id UNIQUEIDENTIFIER not null,
Name TEXT,
SKU TEXT,
MSRP NUMERIC,
Catalog_id UNIQUEIDENTIFIER,
primary key (Id),
constraint FKE86AD8E4B4933C7B foreign key (Catalog_id) references tblCatalog
)
DBG:
create table tblOrder (
Id UNIQUEIDENTIFIER not null,
CreatedOn DATETIME,
primary key (Id)
)
DBG:
create table tbOrderLine (
Id UNIQUEIDENTIFIER not null,
Qty INT,
Price NUMERIC,
Product_id UNIQUEIDENTIFIER,
primary key (Id),
constraint FKD5321C0E8B64AA46 foreign key (Id) references tblOrder,
constraint productId foreign key (Product_id) references tblProduct (Id)
)
DBG: Closing connection
DBG: Disposing of ConnectionProvider.
INF: checking mappings queue
INF: processing one-to-many association mappings
INF: processing one-to-one association property references
INF: processing foreign key constraints
DBG: resolving reference to class: NHibernate.ConsoleTest.ICataglog
DBG: resolving reference to class: NHibernate.ConsoleTest.IOrder
DBG: resolving reference to class: NHibernate.ConsoleTest.IProduct
INF: processing filters (second pass)
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
INF: Using dialect defined converter
INF: Generate SQL with comments: disabled
INF: Initializing connection provider: NHibernate.Connection.DriverConnectionProvider
INF: Configuring ConnectionProvider
INF: Transaction factory: NHibernate.Transaction.AdoNetWithSystemTransactionFactory
INF: Optimize cache for minimal puts: False
INF: Connection release mode: auto
INF: Default batch fetch size: 1
INF: Statistics: disabled
INF: Deleted entity synthetic identifier rollback: disabled
INF: Query translator: NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory
INF: Query provider: NHibernate.Linq.DefaultQueryProvider
INF: Query language substitutions: {'true'='1', 'false'='0'}
INF: cache provider: NHibernate.Cache.NoCacheProvider, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
INF: Order SQL inserts for batching: disabled
INF: Order SQL updates for batching: disabled
DBG: Wrap result sets: disabled
DBG: Batch versioned data: disabled
INF: Batcher factory: NHibernate.AdoNet.NonBatchingBatcherFactory, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
INF: Default flush mode: Auto
INF: Named query checking : enabled
INF: building session factory
DBG: Session factory constructed with filter configurations : {}
DBG: instantiating session factory with properties: {'use_reflection_optimizer'='True', 'connection.provider'='NHibernate.Connection.DriverConnectionProvider', 'connection.driver_class'='NHibernate.Driver.SQLite20Driver, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4', 'dialect'='NHibernate.Dialect.SQLiteDialect, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4', 'hibernate.dialect'='NHibernate.Dialect.SQLiteDialect, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4', 'query.substitutions'='true=1;false=0', 'connection.connection_string'='Data Source=test.db;Version=3;New=True;'}
DBG: Obtaining DbConnection from Driver
DBG: Closing connection
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
DBG: No custom accessors found for entity: NHibernate.ConsoleTest.ICataglog
DBG: Create Instantiator using optimizer for:NHibernate.ConsoleTest.ICataglog
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
DBG: No custom accessors found for entity: NHibernate.ConsoleTest.IProduct
DBG: Create Instantiator using optimizer for:NHibernate.ConsoleTest.IProduct
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
DBG: No custom accessors found for entity: NHibernate.ConsoleTest.IOrder
DBG: Create Instantiator using optimizer for:NHibernate.ConsoleTest.IOrder
INF: Using dialect: NHibernate.Dialect.SQLiteDialect
DBG: No custom accessors found for entity: NHibernate.ConsoleTest.IOrderLine
DBG: Create Instantiator using optimizer for:NHibernate.ConsoleTest.IOrderLine
DBG: Static SQL for collection: NHibernate.ConsoleTest.IOrder.Lines
DBG: Row insert: UPDATE tbOrderLine SET Id = ? WHERE Id = ?
DBG: Row delete: UPDATE tbOrderLine SET Id = null WHERE Id = ? AND Id = ?
DBG: One-shot delete: UPDATE tbOrderLine SET Id = null WHERE Id = ?
DBG: Static SQL for entity: NHibernate.ConsoleTest.ICataglog
DBG: Version select: SELECT Id FROM tblCatalog WHERE Id = ?
DBG: Snapshot select: SELECT icataglog_.Id, icataglog_.Name as name2_0_ FROM tblCatalog icataglog_ WHERE icataglog_.Id=?
DBG: Insert 0: INSERT INTO tblCatalog (Name, Id) VALUES (?, ?)
DBG: Update 0: UPDATE tblCatalog SET Name = ? WHERE Id = ?
DBG: Delete 0: DELETE FROM tblCatalog WHERE Id = ?
DBG: Static select for entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+MergeCascadingAction on entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+RefreshCascadingAction on entity NHibernate.ConsoleTest.ICataglog: SELECT icataglog0_.Id as id1_0_0_, icataglog0_.Name as name2_0_0_ FROM tblCatalog icataglog0_ WHERE icataglog0_.Id=?
DBG: Static SQL for entity: NHibernate.ConsoleTest.IProduct
DBG: Version select: SELECT Id FROM tblProduct WHERE Id = ?
DBG: Snapshot select: SELECT iproduct_.Id, iproduct_.Name as name2_1_, iproduct_.SKU as sku3_1_, iproduct_.MSRP as msrp4_1_, iproduct_.Catalog_id as catalog5_1_ FROM tblProduct iproduct_ WHERE iproduct_.Id=?
DBG: Insert 0: INSERT INTO tblProduct (Name, SKU, MSRP, Catalog_id, Id) VALUES (?, ?, ?, ?, ?)
DBG: Update 0: UPDATE tblProduct SET Name = ?, SKU = ?, MSRP = ?, Catalog_id = ? WHERE Id = ?
DBG: Delete 0: DELETE FROM tblProduct WHERE Id = ?
DBG: Static select for entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+MergeCascadingAction on entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+RefreshCascadingAction on entity NHibernate.ConsoleTest.IProduct: SELECT iproduct0_.Id as id1_1_0_, iproduct0_.Name as name2_1_0_, iproduct0_.SKU as sku3_1_0_, iproduct0_.MSRP as msrp4_1_0_, iproduct0_.Catalog_id as catalog5_1_0_ FROM tblProduct iproduct0_ WHERE iproduct0_.Id=?
DBG: Static SQL for entity: NHibernate.ConsoleTest.IOrder
DBG: Version select: SELECT Id FROM tblOrder WHERE Id = ?
DBG: Snapshot select: SELECT iorder_.Id, iorder_.CreatedOn as createdon2_2_ FROM tblOrder iorder_ WHERE iorder_.Id=?
DBG: Insert 0: INSERT INTO tblOrder (CreatedOn, Id) VALUES (?, ?)
DBG: Update 0: UPDATE tblOrder SET CreatedOn = ? WHERE Id = ?
DBG: Delete 0: DELETE FROM tblOrder WHERE Id = ?
DBG: Static select for entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_0_, iorder0_.CreatedOn as createdon2_2_0_ FROM tblOrder iorder0_ WHERE iorder0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_0_, iorder0_.CreatedOn as createdon2_2_0_ FROM tblOrder iorder0_ WHERE iorder0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_0_, iorder0_.CreatedOn as createdon2_2_0_ FROM tblOrder iorder0_ WHERE iorder0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_0_, iorder0_.CreatedOn as createdon2_2_0_ FROM tblOrder iorder0_ WHERE iorder0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_0_, iorder0_.CreatedOn as createdon2_2_0_ FROM tblOrder iorder0_ WHERE iorder0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+MergeCascadingAction on entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_1_, iorder0_.CreatedOn as createdon2_2_1_, lines1_.Id as id1_3_3_, lines1_.Id as id1_3_0_, lines1_.Qty as qty2_3_0_, lines1_.Price as price3_3_0_, lines1_.Product_id as product4_3_0_ FROM tblOrder iorder0_ left outer join tbOrderLine lines1_ on iorder0_.Id=lines1_.Id WHERE iorder0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+RefreshCascadingAction on entity NHibernate.ConsoleTest.IOrder: SELECT iorder0_.Id as id1_2_1_, iorder0_.CreatedOn as createdon2_2_1_, lines1_.Id as id1_3_3_, lines1_.Id as id1_3_0_, lines1_.Qty as qty2_3_0_, lines1_.Price as price3_3_0_, lines1_.Product_id as product4_3_0_ FROM tblOrder iorder0_ left outer join tbOrderLine lines1_ on iorder0_.Id=lines1_.Id WHERE iorder0_.Id=?
DBG: Static SQL for entity: NHibernate.ConsoleTest.IOrderLine
DBG: Version select: SELECT Id FROM tbOrderLine WHERE Id = ?
DBG: Snapshot select: SELECT iorderline_.Id, iorderline_.Qty as qty2_3_, iorderline_.Price as price3_3_, iorderline_.Product_id as product4_3_ FROM tbOrderLine iorderline_ WHERE iorderline_.Id=?
DBG: Insert 0: INSERT INTO tbOrderLine (Qty, Price, Product_id, Id) VALUES (?, ?, ?, ?)
DBG: Update 0: UPDATE tbOrderLine SET Qty = ?, Price = ?, Product_id = ? WHERE Id = ?
DBG: Delete 0: DELETE FROM tbOrderLine WHERE Id = ?
DBG: Static select for entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+MergeCascadingAction on entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for action NHibernate.Engine.CascadingAction+RefreshCascadingAction on entity NHibernate.ConsoleTest.IOrderLine: SELECT iorderline0_.Id as id1_3_0_, iorderline0_.Qty as qty2_3_0_, iorderline0_.Price as price3_3_0_, iorderline0_.Product_id as product4_3_0_ FROM tbOrderLine iorderline0_ WHERE iorderline0_.Id=?
DBG: Static select for one-to-many NHibernate.ConsoleTest.IOrder.Lines: SELECT lines0_.Id as id1_3_1_, lines0_.Id as id1_3_0_, lines0_.Qty as qty2_3_0_, lines0_.Price as price3_3_0_, lines0_.Product_id as product4_3_0_ FROM tbOrderLine lines0_ WHERE lines0_.Id=?
DBG: initializing class SessionFactoryObjectFactory
DBG: registered: 91098ceea9a442d688d4c88722dcf786(unnamed)
INF: no name configured
DBG: Instantiated session factory
DBG: Checking 0 named HQL queries
DBG: Checking 0 named SQL queries
Opening Session
DBG: Opening Hibernate Session.
DBG: [session-id=e4fb84ae-b37e-4f58-9208-16c36b3b4141] opened session at timestamp: 636545480406, for session factory: [/91098ceea9a442d688d4c88722dcf786]
Starting Transaction
DBG: Begin (Unspecified)
DBG: Obtaining DbConnection from Driver
Saving Product
DBG: saving transient instance
DBG: generated identifier: 473e301d-1f09-49f8-86ec-be710caf7fdd, using strategy: NHibernate.Id.Assigned
DBG: saving [NHibernate.ConsoleTest.IOrder#473e301d-1f09-49f8-86ec-be710caf7fdd]
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrder
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrder
DBG: Wrapped collection in role: NHibernate.ConsoleTest.IOrder.Lines
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrder
INF: cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: NHibernate.ConsoleTest.IOrder.Lines
DBG: cascading to saveOrUpdate: NHibernate.ConsoleTest.IOrderLine
DBG: id unsaved-value strategy UNDEFINED
WRN: Unable to determine if NHibernate.ConsoleTest.OrderLine with assigned identifier 676d8505-ed65-42a3-a225-7612b0c37597 is transient or detached; querying the database. Use explicit Save() or Update() in session to prevent this.
DBG: Getting current persistent state for: [NHibernate.ConsoleTest.IOrderLine#676d8505-ed65-42a3-a225-7612b0c37597]
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: SELECT iorderline_.Id, iorderline_.Qty as qty2_3_, iorderline_.Price as price3_3_, iorderline_.Product_id as product4_3_ FROM tbOrderLine iorderline_ WHERE iorderline_.Id=?
DBG: binding '676d8505-ed65-42a3-a225-7612b0c37597' to parameter: 0
DBG: SELECT iorderline_.Id, iorderline_.Qty as qty2_3_, iorderline_.Price as price3_3_, iorderline_.Product_id as product4_3_ FROM tbOrderLine iorderline_ WHERE iorderline_.Id=@p0;@p0 = 676d8505-ed65-42a3-a225-7612b0c37597 [Type: Guid (0:0:0)]
DBG: Enlist Command
DBG: ExecuteReader took 6 ms
DBG: Opened DbDataReader, open DbDataReaders: 1
DBG: Closed DbDataReader, open DbDataReaders :0
DBG: DataReader was closed after 10 ms
DBG: Closed DbCommand, open DbCommands: 0
DBG: transient instance of: NHibernate.ConsoleTest.IOrderLine
DBG: saving transient instance
DBG: generated identifier: 676d8505-ed65-42a3-a225-7612b0c37597, using strategy: NHibernate.Id.Assigned
DBG: saving [NHibernate.ConsoleTest.IOrderLine#676d8505-ed65-42a3-a225-7612b0c37597]
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrderLine
DBG: cascading to saveOrUpdate: NHibernate.ConsoleTest.IProduct
DBG: id unsaved-value strategy UNDEFINED
WRN: Unable to determine if NHibernate.ConsoleTest.Product with assigned identifier aaa2484f-1430-45ce-9d9f-554e3b97ffe7 is transient or detached; querying the database. Use explicit Save() or Update() in session to prevent this.
DBG: Getting current persistent state for: [NHibernate.ConsoleTest.IProduct#aaa2484f-1430-45ce-9d9f-554e3b97ffe7]
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: SELECT iproduct_.Id, iproduct_.Name as name2_1_, iproduct_.SKU as sku3_1_, iproduct_.MSRP as msrp4_1_, iproduct_.Catalog_id as catalog5_1_ FROM tblProduct iproduct_ WHERE iproduct_.Id=?
DBG: binding 'aaa2484f-1430-45ce-9d9f-554e3b97ffe7' to parameter: 0
DBG: SELECT iproduct_.Id, iproduct_.Name as name2_1_, iproduct_.SKU as sku3_1_, iproduct_.MSRP as msrp4_1_, iproduct_.Catalog_id as catalog5_1_ FROM tblProduct iproduct_ WHERE iproduct_.Id=@p0;@p0 = aaa2484f-1430-45ce-9d9f-554e3b97ffe7 [Type: Guid (0:0:0)]
DBG: Enlist Command
DBG: ExecuteReader took 0 ms
DBG: Opened DbDataReader, open DbDataReaders: 1
DBG: Closed DbDataReader, open DbDataReaders :0
DBG: DataReader was closed after 3 ms
DBG: Closed DbCommand, open DbCommands: 0
DBG: transient instance of: NHibernate.ConsoleTest.IProduct
DBG: saving transient instance
DBG: generated identifier: aaa2484f-1430-45ce-9d9f-554e3b97ffe7, using strategy: NHibernate.Id.Assigned
DBG: saving [NHibernate.ConsoleTest.IProduct#aaa2484f-1430-45ce-9d9f-554e3b97ffe7]
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IProduct
DBG: cascading to saveOrUpdate: NHibernate.ConsoleTest.ICataglog
DBG: id unsaved-value strategy UNDEFINED
WRN: Unable to determine if NHibernate.ConsoleTest.Catalog with assigned identifier a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd is transient or detached; querying the database. Use explicit Save() or Update() in session to prevent this.
DBG: Getting current persistent state for: [NHibernate.ConsoleTest.ICataglog#a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd]
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: SELECT icataglog_.Id, icataglog_.Name as name2_0_ FROM tblCatalog icataglog_ WHERE icataglog_.Id=?
DBG: binding 'a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd' to parameter: 0
DBG: SELECT icataglog_.Id, icataglog_.Name as name2_0_ FROM tblCatalog icataglog_ WHERE icataglog_.Id=@p0;@p0 = a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd [Type: Guid (0:0:0)]
DBG: Enlist Command
DBG: ExecuteReader took 0 ms
DBG: Opened DbDataReader, open DbDataReaders: 1
DBG: Closed DbDataReader, open DbDataReaders :0
DBG: DataReader was closed after 5 ms
DBG: Closed DbCommand, open DbCommands: 0
DBG: transient instance of: NHibernate.ConsoleTest.ICataglog
DBG: saving transient instance
DBG: generated identifier: a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd, using strategy: NHibernate.Id.Assigned
DBG: saving [NHibernate.ConsoleTest.ICataglog#a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd]
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IProduct
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IProduct
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IProduct
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrderLine
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrderLine
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrderLine
INF: done cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: NHibernate.ConsoleTest.IOrder.Lines
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrder
DBG: Start Commit
DBG: before transaction completion
DBG: flushing session
DBG: processing flush-time cascades
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrder
INF: cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: NHibernate.ConsoleTest.IOrder.Lines
DBG: cascading to saveOrUpdate: NHibernate.ConsoleTest.IOrderLine
DBG: persistent instance of: NHibernate.ConsoleTest.IOrderLine
DBG: ignoring persistent instance
DBG: object already associated with session: [NHibernate.ConsoleTest.IOrderLine#676d8505-ed65-42a3-a225-7612b0c37597]
INF: done cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: NHibernate.ConsoleTest.IOrder.Lines
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrder
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IProduct
DBG: cascading to saveOrUpdate: NHibernate.ConsoleTest.ICataglog
DBG: persistent instance of: NHibernate.ConsoleTest.ICataglog
DBG: ignoring persistent instance
DBG: object already associated with session: [NHibernate.ConsoleTest.ICataglog#a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd]
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IProduct
INF: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrderLine
DBG: cascading to saveOrUpdate: NHibernate.ConsoleTest.IProduct
DBG: persistent instance of: NHibernate.ConsoleTest.IProduct
DBG: ignoring persistent instance
DBG: object already associated with session: [NHibernate.ConsoleTest.IProduct#aaa2484f-1430-45ce-9d9f-554e3b97ffe7]
INF: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: NHibernate.ConsoleTest.IOrderLine
DBG: dirty checking collections
DBG: Flushing entities and processing referenced collections
DBG: Collection found: [NHibernate.ConsoleTest.IOrder.Lines#473e301d-1f09-49f8-86ec-be710caf7fdd], was: [<unreferenced>] (initialized)
DBG: Processing unreferenced collections
DBG: Scheduling collection removes/(re)creates/updates
DBG: Flushed: 4 insertions, 0 updates, 0 deletions to 4 objects
DBG: Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
DBG: listing entities:
DBG: NHibernate.ConsoleTest.Order
DBG: NHibernate.ConsoleTest.Catalog
DBG: NHibernate.ConsoleTest.Product
DBG: NHibernate.ConsoleTest.OrderLine
DBG: executing flush
DBG: Registering flush begin
DBG: Inserting entity: [NHibernate.ConsoleTest.IOrder#473e301d-1f09-49f8-86ec-be710caf7fdd]
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: INSERT INTO tblOrder (CreatedOn, Id) VALUES (?, ?)
DBG: Dehydrating entity: [NHibernate.ConsoleTest.IOrder#473e301d-1f09-49f8-86ec-be710caf7fdd]
DBG: binding '2/18/2018 10:53:56 AM' to parameter: 0
DBG: binding '473e301d-1f09-49f8-86ec-be710caf7fdd' to parameter: 1
DBG: INSERT INTO tblOrder (CreatedOn, Id) VALUES (@p0, @p1);@p0 = 2018-02-18T10:53:56.8802275-05:00 [Type: DateTime (0:0:0)], @p1 = 473e301d-1f09-49f8-86ec-be710caf7fdd [Type: Guid (0:0:0)]
DBG: Enlist Command
DBG: ExecuteNonQuery took 7 ms
DBG: Inserting entity: [NHibernate.ConsoleTest.ICataglog#a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd]
DBG: ExecuteBatch for 1 statements took 0 ms
DBG: Closed DbCommand, open DbCommands: 0
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: INSERT INTO tblCatalog (Name, Id) VALUES (?, ?)
DBG: Dehydrating entity: [NHibernate.ConsoleTest.ICataglog#a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd]
DBG: binding 'Catalog 1' to parameter: 0
DBG: binding 'a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd' to parameter: 1
DBG: INSERT INTO tblCatalog (Name, Id) VALUES (@p0, @p1);@p0 = 'Catalog 1' [Type: String (0:0:0)], @p1 = a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd [Type: Guid (0:0:0)]
DBG: Enlist Command
DBG: ExecuteNonQuery took 1 ms
DBG: Inserting entity: [NHibernate.ConsoleTest.IProduct#aaa2484f-1430-45ce-9d9f-554e3b97ffe7]
DBG: ExecuteBatch for 1 statements took 0 ms
DBG: Closed DbCommand, open DbCommands: 0
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: INSERT INTO tblProduct (Name, SKU, MSRP, Catalog_id, Id) VALUES (?, ?, ?, ?, ?)
DBG: Dehydrating entity: [NHibernate.ConsoleTest.IProduct#aaa2484f-1430-45ce-9d9f-554e3b97ffe7]
DBG: binding 'Sample Product' to parameter: 0
DBG: binding '123456789' to parameter: 1
DBG: binding '1' to parameter: 2
DBG: binding 'a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd' to parameter: 3
DBG: binding 'aaa2484f-1430-45ce-9d9f-554e3b97ffe7' to parameter: 4
DBG: INSERT INTO tblProduct (Name, SKU, MSRP, Catalog_id, Id) VALUES (@p0, @p1, @p2, @p3, @p4);@p0 = 'Sample Product' [Type: String (0:0:0)], @p1 = '123456789' [Type: String (0:0:0)], @p2 = 1 [Type: Decimal (0:0:0)], @p3 = a1cc8b2b-0bdd-4412-8a47-fa9a52ce15cd [Type: Guid (0:0:0)], @p4 = aaa2484f-1430-45ce-9d9f-554e3b97ffe7 [Type: Guid (0:0:0)]
DBG: Enlist Command
DBG: ExecuteNonQuery took 0 ms
DBG: Inserting entity: [NHibernate.ConsoleTest.IOrderLine#676d8505-ed65-42a3-a225-7612b0c37597]
DBG: ExecuteBatch for 1 statements took 0 ms
DBG: Closed DbCommand, open DbCommands: 0
DBG: Opened new DbCommand, open DbCommands: 1
DBG: Building an DbCommand object for the SqlString: INSERT INTO tbOrderLine (Qty, Price, Product_id, Id) VALUES (?, ?, ?, ?)
DBG: Dehydrating entity: [NHibernate.ConsoleTest.IOrderLine#676d8505-ed65-42a3-a225-7612b0c37597]
DBG: binding '1' to parameter: 0
DBG: binding '1' to parameter: 1
DBG: Closed DbCommand, open DbCommands: 0
ERR: NHibernate.PropertyValueException: Error dehydrating property value for NHibernate.ConsoleTest.IOrderLine.Product ---> NHibernate.HibernateException: Unable to resolve property: Id
at NHibernate.Tuple.Entity.EntityMetamodel.GetPropertyIndex(String propertyName)
at NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetPropertyValue(Object entity, String propertyPath)
at NHibernate.Persister.Entity.AbstractEntityPersister.GetPropertyValue(Object obj, String propertyName)
at NHibernate.Type.EntityType.GetReferenceValue(Object value, ISessionImplementor session)
at NHibernate.Type.ManyToOneType.NullSafeSet(DbCommand st, Object value, Int32 index, Boolean[] settable, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, DbCommand statement, ISessionImplementor session, Int32 index)
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, DbCommand statement, ISessionImplementor session, Int32 index)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
ERR: Could not synchronize database state with session
DBG: Registering flush end
DBG: DbTransaction disposed.
DBG: Aggressively releasing database connection
DBG: Closing connection
DBG: transaction completion
DBG: [session-id=e4fb84ae-b37e-4f58-9208-16c36b3b4141] running ISession.Dispose()
DBG: [session-id=e4fb84ae-b37e-4f58-9208-16c36b3b4141] executing real Dispose(True)
DBG: closing session
DBG: running BatcherImpl.Dispose(true)
Exception: NHibernate.PropertyValueException: Error dehydrating property value for NHibernate.ConsoleTest.IOrderLine.Product ---> NHibernate.HibernateException: Unable to resolve property: Id
at NHibernate.Tuple.Entity.EntityMetamodel.GetPropertyIndex(String propertyName)
at NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetPropertyValue(Object entity, String propertyPath)
at NHibernate.Persister.Entity.AbstractEntityPersister.GetPropertyValue(Object obj, String propertyName)
at NHibernate.Type.EntityType.GetReferenceValue(Object value, ISessionImplementor session)
at NHibernate.Type.ManyToOneType.NullSafeSet(DbCommand st, Object value, Int32 index, Boolean[] settable, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, DbCommand statement, ISessionImplementor session, Int32 index)
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, DbCommand statement, ISessionImplementor session, Int32 index)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Impl.SessionImpl.FlushBeforeTransactionCompletion()
at NHibernate.Impl.SessionImpl.BeforeTransactionCompletion(ITransaction tx)
at NHibernate.Transaction.AdoTransaction.Commit()
at NHibernate.ConsoleTest.Program.Main(String[] args) in E:\Projects\NHibernate.ConsoleTest\Program.cs:line 38
InnerException: NHibernate.HibernateException: Unable to resolve property: Id
at NHibernate.Tuple.Entity.EntityMetamodel.GetPropertyIndex(String propertyName)
at NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetPropertyValue(Object entity, String propertyPath)
at NHibernate.Persister.Entity.AbstractEntityPersister.GetPropertyValue(Object obj, String propertyName)
at NHibernate.Type.EntityType.GetReferenceValue(Object value, ISessionImplementor session)
at NHibernate.Type.ManyToOneType.NullSafeSet(DbCommand st, Object value, Int32 index, Boolean[] settable, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, DbCommand statement, ISessionImplementor session, Int32 index)
Press <ENTER> to exit....
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.ICataglog, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tblCatalog">
<id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="assigned" />
</id>
<property name="Name" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Name" />
</property>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.IOrder, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tblOrder">
<id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="assigned" />
</id>
<bag cascade="all" name="Lines">
<key>
<column name="Id" />
</key>
<one-to-many class="NHibernate.ConsoleTest.IOrderLine, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
<property name="CreatedOn" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="CreatedOn" />
</property>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.IOrderLine, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tbOrderLine">
<id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="assigned" />
</id>
<property name="Qty" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Qty" />
</property>
<property name="Price" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Price" />
</property>
<many-to-one cascade="save-update" class="NHibernate.ConsoleTest.IProduct, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" foreign-key="productId" name="Product" property-ref="Id">
<column name="Product_id" />
</many-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="NHibernate.ConsoleTest.IProduct, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="tblProduct">
<id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="assigned" />
</id>
<property name="Name" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Name" />
</property>
<property name="SKU" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="SKU" />
</property>
<property name="MSRP" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="MSRP" />
</property>
<many-to-one cascade="save-update" class="NHibernate.ConsoleTest.ICataglog, NHibernate.ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Catalog">
<column name="Catalog_id" />
</many-to-one>
</class>
</hibernate-mapping>
using System;
using System.Collections.Generic;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using NHibernate.Tool.hbm2ddl;
namespace NHibernate.ConsoleTest
{
class Program
{
static void Main(string[] args)
{
try
{
var c = new Catalog { Name = "Catalog 1" };
var p = new Product { Name = "Sample Product", SKU = "123456789", MSRP = (decimal)1.0, Catalog = c };
var ol = new OrderLine { Product = p, Price = p.MSRP, Qty = 1 };
var o = new Order { CreatedOn = DateTime.Now, Lines = new List<IOrderLine> { ol } };
if (System.IO.File.Exists("test.db"))
{
System.IO.File.Delete("test.db");
}
Console.WriteLine("Creating Session Factory");
var sessionFactory = NHibernateUtils.CreateSessionFactory(SQLiteConfiguration.Standard.UsingFile("test.db"));
Console.WriteLine("Opening Session");
using (var session = sessionFactory.OpenSession())
{
Console.WriteLine("Starting Transaction");
using (var transaction = session.BeginTransaction())
{
Console.WriteLine("Saving Product");
session.Save(typeof(IOrder).FullName, o);
transaction.Commit();
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex);
if (ex.InnerException != null) Console.WriteLine("InnerException: {0}", ex.InnerException);
}
Console.WriteLine("Press <ENTER> to exit....");
Console.ReadLine();
}
}
#region Interfaces
public interface IEntity
{
Guid Id { get; set; }
}
public interface ICataglog : IEntity
{
string Name { get; set; }
}
public interface IProduct : IEntity
{
string Name { get; set; }
string SKU { get; set; }
decimal MSRP { get; set; }
ICataglog Catalog { get; set; }
}
public interface IOrder : IEntity
{
DateTime CreatedOn { get; set; }
IList<IOrderLine> Lines { get; set; }
}
public interface IOrderLine : IEntity
{
IProduct Product { get; set; }
int Qty { get; set; }
decimal Price { get; set; }
}
#endregion Interfaces
#region Concreate Classes
public class EntityBase : IEntity
{
public virtual Guid Id { get; set; } = Guid.NewGuid();
}
public class Catalog : EntityBase, ICataglog
{
public string Name { get; set; }
}
public class Product : EntityBase, IProduct
{
public virtual string Name { get; set; }
public virtual string SKU { get; set; }
public virtual decimal MSRP { get; set; }
public ICataglog Catalog { get; set; }
}
public class Order : EntityBase, IOrder
{
public virtual DateTime CreatedOn { get; set; }
public virtual IList<IOrderLine> Lines { get; set; }
}
public class OrderLine : EntityBase, IOrderLine
{
#region Implementation of IOrderLine
public IProduct Product { get; set; }
public int Qty { get; set; }
public decimal Price { get; set; }
#endregion
}
#endregion Concreate Classes
#region Class Maps
public class CatalogMap : ClassMap<ICataglog>
{
public CatalogMap()
{
Table("tblCatalog");
Id(x => x.Id)
.Column("Id")
.GeneratedBy.Assigned();
Map(x => x.Name);
}
}
public class ProductMap : ClassMap<IProduct>
{
public ProductMap()
{
Table("tblProduct");
Id(x => x.Id)
.Column("Id")
.GeneratedBy.Assigned();
Map(x => x.Name);
Map(x => x.SKU);
Map(x => x.MSRP);
References(x => x.Catalog)
.Cascade.SaveUpdate();
}
}
public class OrderMap : ClassMap<IOrder>
{
public OrderMap()
{
Table("tblOrder");
Id(x => x.Id)
.Column("Id")
.GeneratedBy.Assigned();
Map(x => x.CreatedOn);
HasMany(x => x.Lines)
.Cascade.All()
.KeyColumns.Add("Id");
}
}
public class OrderLineMap : ClassMap<IOrderLine>
{
public OrderLineMap()
{
Table("tbOrderLine");
Id(x => x.Id)
.Column("Id")
.GeneratedBy.Assigned();
Map(x => x.Qty);
Map(x => x.Price);
References(x => x.Product)
.Cascade.SaveUpdate()
.PropertyRef(x => x.Id)
.ForeignKey("productId");
}
}
#endregion Class Maps
public static class NHibernateUtils
{
public static ISessionFactory CreateSessionFactory(IPersistenceConfigurer persistenceConfigurer)
{
NHibernate.LoggerProvider.SetLoggersFactory(new ConsoleLoggingFactory());
return Fluently.Configure()
.Database(persistenceConfigurer)
.Mappings(m =>
{
m.FluentMappings.Add<CatalogMap>();
m.FluentMappings.Add<ProductMap>();
m.FluentMappings.Add<OrderMap>();
m.FluentMappings.Add<OrderLineMap>();
m.FluentMappings.ExportTo(System.Environment.CurrentDirectory);
})
.ExposeConfiguration(c => new SchemaExport(c).Create(false, true))
.BuildConfiguration()
.BuildSessionFactory();
}
}
#region Console Logger
public class ConsoleLoggingFactory : ILoggerFactory
{
#region Implementation of ILoggerFactory
public IInternalLogger LoggerFor(string keyName)
{
return new ConsoleLogger();
}
public IInternalLogger LoggerFor(System.Type type)
{
return new ConsoleLogger();
}
#endregion
}
public class ConsoleLogger : IInternalLogger
{
#region Implementation of IInternalLogger
public void Error(object message)
{
Console.Write("ERR: ");
Console.WriteLine(message);
}
public void Error(object message, Exception exception)
{
Console.Write("ERR: ");
Console.WriteLine(exception.ToString());
Console.Write("ERR: ");
Console.WriteLine(message);
}
public void ErrorFormat(string format, params object[] args)
{
Console.Write("ERR: ");
Console.WriteLine(format, args);
}
public void Fatal(object message)
{
Console.Write("FTL: ");
Console.WriteLine(message);
}
public void Fatal(object message, Exception exception)
{
Console.Write("FTL: ");
Console.WriteLine(exception.ToString());
Console.Write("FTL: ");
Console.WriteLine(message);
}
public void Debug(object message)
{
Console.Write("DBG: ");
Console.WriteLine(message);
}
public void Debug(object message, Exception exception)
{
Console.Write("DBG: ");
Console.WriteLine(exception.ToString());
Console.Write("DBG: ");
Console.WriteLine(message);
}
public void DebugFormat(string format, params object[] args)
{
Console.Write("DBG: ");
Console.WriteLine(format, args);
}
public void Info(object message)
{
Console.Write("INF: ");
Console.WriteLine(message);
}
public void Info(object message, Exception exception)
{
Console.Write("INF: ");
Console.WriteLine(exception.ToString());
Console.Write("INF: ");
Console.WriteLine(message);
}
public void InfoFormat(string format, params object[] args)
{
Console.Write("INF: ");
Console.WriteLine(format, args);
}
public void Warn(object message)
{
Console.Write("WRN: ");
Console.WriteLine(message);
}
public void Warn(object message, Exception exception)
{
Console.Write("WRN: ");
Console.WriteLine(exception.ToString());
Console.Write("WRN: ");
Console.WriteLine(message);
}
public void WarnFormat(string format, params object[] args)
{
Console.Write("WRN: ");
Console.WriteLine(format, args);
}
public bool IsErrorEnabled => true;
public bool IsFatalEnabled => true;
public bool IsDebugEnabled => true;
public bool IsInfoEnabled => true;
public bool IsWarnEnabled => true;
#endregion
}
#endregion Console Logger
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment