I'm new in NHibernate and I have some doubts. I'll put my code bellow and then I'll explain.
My tables:
My classes:
public class IntegratorModel : PGIBaseModel<int>, IIntegratorModel
{
public virtual string Identifier { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
public class ClientModel : PGIBaseModel<int>, IClientModel
{
public virtual string Name { get; set; }
public virtual string TokenPGI { get; set; }
public virtual IIntegratorModel Integrator { get; set; }
}
My mappings using Fluent:
public class IntegratorMappingOverride : IAutoMappingOverride<IntegratorModel>
{
public virtual void Override(AutoMapping<IntegratorModel> mapping)
{
mapping.Map(model => model.Identifier).Column("Identifier").Length(4);
mapping.Map(model => model.Name).Column("Name").Length(200);
mapping.Map(model => model.Description).Column("Description").Length(2000);
}
}
public class ClientMappingOverride : IAutoMappingOverride<ClientModel>
{
public virtual void Override(AutoMapping<ClientModel> mapping)
{
mapping.Map(model => model.Name).Column("Name").Length(200);
mapping.Map(model => model.TokenPGI).Column("TokenPGI").Length(50);
mapping.References<IntegratorModel>(model => model.Integrator);
}
}
I'm saving IntegratorModel previously in another moment, so when I'm inserting a new ClientModel I already have the IntegratorID, so it's ok.
My question is when I'm updating ClientModel and I want to change IntegratorID in the database, I'm doing something like this:
IClientModel model = this.GetModelFromPost();
model.Integrator = integratorBLL.LoadByID(context.Request.Form["IntegratorID"]));
clientBLL.Save(model);
integratorBLL.LoadByID just will call ISession.Load from NHibernate. Maybe I'm wrong, but Load doesn't hit the database in this moment.
My question is if what I'm doing is correct. In this case, won't be easier if I had some property IntegratorID directly in ClientModel e just updated it?
Cause, in my architeture, I have to call my BLL of Integrator, call Load and then set the return in ClientModel property.
This code works, but cause I'm new at Nhibernate, I think that probably there's another way to do it better.