c# - Child objects not being populated only when using SQLite (Works in SQL Server) -
i have fluent nhibernate mapping works expected when run against actual sql server database not populting collection of child objects when run against sqlite. structure being queried self-referential account hierarchy each account may have 1 parent , 0-m child accounts. parent account getting loaded correctly, list of child objects coming null
.
the basic table structure looks (note: i've left out of fields don't have issue.)
account ------- accountid title parentaccountid
the account class looks like:
public class account { public virtual int id { get; set; } public virtual string title { get; set; } public virtual account parentaccount { get; set; } public virtual ilist<account> childaccounts { get; set; } }
the mapping account class looks like:
public class accountmap : classmap<account> { public accountmap() { table("accounts"); id(a => a.id).column("accountid").generatedby.assigned(); map(a => a.title); hasmany<account>(a => a.childaccounts) .table("accounts") .keycolumn("parentaccountid") .foreignkeyconstraintname("accountid") .orderby("title") .inverse(); references<account>(a => a.parentaccount).column("parentaccountid"); } }
the data in accounts table in sqlite database when i'm trying retrieve account id:
id title parentaccountid -- ----- --------------- 1 account1 null 2 account2 1 3 account3 2 4 account4 2
when make call session.get<account>(2)
following object:
{ id: 2, title: "account2", parentaccount: { id: 1, title: "account1", parentaccount: null, childaccounts: null }, childaccounts: null }
running same call against real sql server database return:
{ id: 2, title: "account2", parentaccount: { id: 1, title: "account1", parentaccount: null, childaccounts: { id: 2, title: "account2", parentaccount: { ... }, childaccounts: { ... } } }, childaccounts: [ { id: 3, title: "account3", parentaccount: { id: 2, title: "account2", parentaccount: { ... }, childaccounts: { ... } }, childaccounts: null }, { id: 4, title: "account4", parentaccount: { id: 2, title: "account2", parentaccount: { ... }, childaccounts: { ... } }, childaccounts: null } ] }
i don't understand why working in sql server not in sqlite, makes writing test make sure mappings , repository code works correctly, difficult.
have tried profile sqlite db using sql profiler? i'm assuming profiler works sqlite i've never tried it.
another thing @ nhibernate log file. when have problems these 2 tools start.
Comments
Post a Comment