nhibernate - Fluent NH - illegal access to loading collection -


I have this error in translated collections in categories: Invalid access to load archive.

  Public category category: entity {public category () {categories translated = new list & lt; Category accredited & gt; (); } The public virtual class parent {receives; Set; } Public Virtual String {get} Set; } Public Virtual ILIT & Lt; Classified translated & gt; Categories Translated {get; Set; }} Public class category translated: unit {public category citation {} {} public virtual category category {received; Set; } Public virtual language type language {get; Set; } Public Virtual String {get} Set; }} Public Zero Override (Automapping & lt; Category & gt; Mapping) {mapping.HasMany (x => x.CategoriesTranslated). Inverted () .Cascade.All (); } Public Zero Override (automation & lt; category provider & gt; mapping) {mapping. Reference (x => x.Category); }  

SQL:

  Make Table Category ([ID] small primary primary identity (1,1), [parent] small faucet , [Name] Varchar (50) tap is not unique; replace table [category] insert fk_Category_Category foreign key (parent) reference category (id) go table category ([id] minor primary primary identification (1,1) , [Class] small tap, [language] tinton faucet, [name] varchar (50) not faucet, change the table [ Translated] Insert fk_CategoryTranslated_Category Foreign Key (Category) Reference Category (ID) Go  

Where is this wrong?

Link to updated HBM generator:

Category:

Category translated:

I think That is to do with the construction of the list inside the constructor, especially if you have left a default CTO for NHib and he is trying to set up before preparing the NHib list The other complexity here is that you have bi-directional relationships and try to get it in the list before the category translated list can be created.

I suspect that this is the only solution, but there is a pattern I use that should solve the error:

  /// & lt; Summary & gt; Gets .... & lt; / Summary & gt; /// & lt; Comment & gt; It is available to customers outside of the domain. & Lt; / Remark & ​​gt; Public virtual IEnumerable & lt; Category & gt; Restricted categories {get {return} built-in conversion categories; }} /// & lt; Summary & gt; Vertical property which maintains the set of translated categories: /// & lt; Items & gt; is available; & Lt; Cref = "category" /> To maintain data integrity & Lt; / Item & gt; /// & lt; Item & gt; Lazily immediately & lt; See cref = "list {T}" /> When it is required. & Lt; / Item & gt; /// & lt; Item & gt; The property has been mapped for NHibernate, private & lt; Cref = "_ categoriesTranslated" /> The field is set here. & Lt; / Item & gt; /// & lt; / List & gt; /// & lt; / Summary & gt; Protected Internal Virtual ILIT & Lt; Category & gt; _InternalCategoriesTranslated {get {return _categoriesTranslated ?? (_categoriesTranslated = new list & lt; grade & gt; ()); } Set {_categoriesTranslated = value; }} Private ILIT & Lt; Staffmember & gt; _categoriesTranslated;  

You now have to set your mapping to access the private field, so assume that you use my casing preferences here, you will have:

  Public Zero Override (Automapping  Mapping) {Mapping. Hashmani (x => x.CategoriesTranslated). Inverted (). Access CamelCasefield (CamelCasePrefix.Underscore) .Cascade.All (); }  

Edit Htt,

============

_Internal Collection also gives two- Child of directional relationship, classified translation in this case, a hook, as shown in the code given below:

  Public Virtual Class Restricted Category Restricted {get {return _categoryTranslated; } Set {if (_categoryTranslated! = Null) {// Existing relation _categoryTranslated._InternalCategoryTranslated.Remove (this) separation; } _categoryTranslated = value; If (value! = Null) {// Association _categoryTranslated._InternalCategoryTranslated.Add (this); }}} Private category translated _category translation;  

Comments