c# - Nhibernate Best way to mapping Parent > Child -


I am new to NHibernate and I have some doubts. I will enter my code and then I will explain.

My table: https: //dl.dropbox.com/u/423844/map% 20db.png

My classes:

  Public class integrated manager: PGIBaseModel & lt; Int & gt;, IIntegratorModel {public virtual string identifier {get; Set; } Public Virtual String {get} Set; } Public Virtual String Description {get; Set; }} Public Class Client Models: PGIBAS MODEL & lt; Int & gt;, IClientModel {public virtual string name {get; Set; } Public Virtual String TokenPGI {get; Set; } Received Public Virtual IIntegrator Model Integrator; Set; }}   

Mapping using flats:

  Public class integrated mapping override: IAutoMappingOverride & lt; Integrator Module & gt; {Public Virtual Zero Override (Auto Mapping & LT; Integrator Module & gt; Mapping) {Mapping. Map (model = & gt; model identifier). Columns ("Identifier"). Length (4); Mapping Map (model = & gt; model.Name). Column ("name"). Length (200); Mapping Map (model = & gt; model.descriptation). Columns ("Details"). Length (2000); }} Public class clientmapping override: IAutoMappingOverride & lt; ClientModel & gt; {Public Virtual Zero Override (Automapping & lt; ClientModel> Mapping) {mapping.Map (Model = & gt; Model. Name). Column ("name"). Length (200); Mapping Map (model => Model. TokenPGI). Columns ("tokenpji") Length (50); Mapping Context and lieutenant; Integrator Module & gt; (Model => model.Integrator); }}   

I am saving IntegatorModel in another moment before, so when I am putting a new client model, I already have IntegratorID, so it's OK.

My question is, when I am updating the client modal and want to change IntegratorID in the database, then I am doing something like this:

  IClientModel model = This.GetModelFromPost (); Model.Integrator = integratorBLL.LoadByID (context.Request.Form ["IntegratorID"])); ClientBLL.Save (model);   

The integrator will call the BLL.loadbad bus eSation. Load from NHibernate Maybe I'm wrong, but load does not kill the database at this moment.

My question is what I am doing is correct. In this case, if I had some property integrator ID directly in the client modal, would not it be easy?

Because, in my arbitrator, call me your BLL of Integator, load it, and then set the return in the client modal property.

This code works, but I'm new to Nabin, so I think it's probably another way to do better.

session.Load () is for this scenario and its benefit is That object proxy treats you like a real object, so after you have only set up an ID, there is no broken model and you want to use the client modal editor later. This change does not break track because NHib null & gt; Not initial and null & gt;

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -