Having three types (application, category and package) reference each other
bidirectionally is not really a good idea. At least, one side of each
relation should be marked as inverse. Additionally, you are getting into
trouble as soon as you are updating or deleting data with such a model.

I recommend making the relations to category unidirectional, such that
category does not have a list of applications or packages. If you need to
find packages or applications for a category, you can use a query. If the
relation between application and package remains bidirectional, you should
mark one side of it as inverse (presumably package).

On the type that has the inverse end of the relation, the collection
property should be protected internal, offering only ReadOnlyCollection or
IEnumerable<T> publicly. This is by the way recommended for all
bidirectional collection-valued properties, with Add/Remove-methods for all
publicly available collections, that also set the inverse end of the
relation so that all relations are always synchronized.

As for the SessionScope and the DAL, you can always build a fools
indirection, using SessionScope by delegation in your own type.
Oversimplified example:

public class UnitOfWork : IDisposable
{
  private SessionScope scope;
  public UnitOfWork()
  {
    scope = new SessionScope();
  }
  public void Dispose()
  {
    if (scope != null) scope.Dispose();
  }
}

-Markus

2009/4/28 Corisco <[email protected]>

>
> Jason, thanks for the tip, I'll give it a try. However, if anyone else
> have a different idea all the help is welcomed
>
> By the way, sorry for the duplicated post!!
>
> On Apr 28, 2:42 pm, Jason Meckley <[email protected]> wrote:
> > just because the data access is located in a remote dll doesn't mean
> > you cannot use Session/Request. You can use another object to delegate
> > the creation/destruction of the session in relation to the request
> > which references the DAL assembly.  For more information see how
> > Caste.NHibernateFacility.SessionManager works.
> >
> > If this isn't an option then you need to preload all the data you need
> > when you make the call to the DAL. Either than or pass the entity back
> > to the DAL, merge with the current session, and then load other
> > properties.
> >
> > On Apr 28, 6:09 am, Corisco <[email protected]> wrote:
> >
> > > I am developing somekind of CMS web app. After few additions to the DB
> > > it experiences huge performance problems. I'm new to the
> > > ActiveRecord / NHibernate world. So probably I'm making some
> > > configuration mistakes, but I'm not able to solve it.
> >
> > > I have tried using lazy relations and it seems to improve a lot. But
> > > now I'm getting the famous 'Failed to lazily initialize a collection -
> > > no session' error. However, I have to encapsulate all db related
> > > actions in a dll apart so I cannot enable the session-per-request as
> > > suggested inhttp://
> using.castleproject.org/display/AR/Enable+Session+per+Request
> >
> > > I don't even know if the lazy relations solution is the correct
> > > approach. Any clue?
> >
> > > Thanks in advance!!
> >
> > > I'm initializing ActiveRecord through an InPlaceConfigurationSource.
> > > The basic scheme, designed with ActiveWriter, looks like this
> > > (summarized)
> >
> > >
> |------------(n-m)--------------------->>CMSTransientCategory<<-----------------(n-m)
> --------|
> >
> > > |
> > > |
> > > |
> > > |
> > >
> |--->>CMSTransientApplication<<---------(n-m)------------->>CMSTransientPackage<<---|
> >
> > >            |
> > >            |
> > >            |
> > >            |---------(1-n)----->>CMSTransientFileInstance<<----(n-
> > > m)----->>CMSTransientOperatingSystem
> >
> > > |         |
> >
> > > |         |
> > > CMSTransientFileInformation<<----(1-n)----|         |---(1-n)--
> >
> > > >>CMSTransientContentType
> >
> > > These are the parameters used for initialization
> >
> > > isWeb=True
> > > isDebug=False
> > > hibernate.connection.driver_class=NHibernate.Driver.SqlClientDriver
> > > hibernate.dialect=NHibernate.Dialect.MsSql2005Dialect
> > >
> hibernate.connection.provider=NHibernate.Connection.DriverConnectionProvider
> > >
> hibernate.connection.connection_string=Server=192.168.1.202\sqlexpress;Database=mssf;Uid=******;Pwd=*********;
> >
> > > And the generated classes are
> >
> > >  [ActiveRecord()]
> > >     public partial class CMSTransientCategory :
> > > CMSTransientEntity<CMSTransientCategory> {
> >
> > >         private IList<CMSTransientPackage> _packages;
> > >         private IList<CMSTransientApplication> _applications;
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientPackage),
> > > ColumnRef="PackageId", ColumnKey="CategoryId",
> > > Table="Packages2Categories")]
> > >         public virtual IList<CMSTransientPackage> Packages {
> > >             get {return this._packages;}
> > >             set {this._packages = value;}
> > >         }
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientApplication),
> > > ColumnRef="ApplicationId", ColumnKey="CategoryId",
> > > Table="Applications2Categories")]
> > >         public virtual IList<CMSTransientApplication> Applications {
> > >             get {return this._applications;}
> > >             set{this._applications = value;}
> > >         }
> > >     }
> >
> > >     [ActiveRecord()]
> > >     public partial class CMSTransientPackage :
> > > CMSTransientEntity<CMSTransientPackage> {
> >
> > >         private IList<CMSTransientCategory> _categories;
> > >         private IList<CMSTransientApplication> _applications;
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientCategory),
> > > ColumnRef="CategoryId", ColumnKey="PackageId",
> > > Table="Packages2Categories")]
> > >         public virtual IList<CMSTransientCategory> Categories {
> > >             get {return this._categories;}
> > >                                                 set{this._categories =
> value;}
> > >         }
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientApplication),
> > > ColumnRef="ApplicationId", ColumnKey="PackageId",
> > > Table="Applications2Packages")]
> > >         public virtual IList<CMSTransientApplication> Applications {
> > >             get {return this._applications;}
> > >                                                 set{this._applications
> = value;}
> > >         }
> > >     }
> >
> > >     [ActiveRecord()]
> > >     public partial class CMSTransientApplication :
> > > CMSTransientEntity<CMSTransientApplication> {
> >
> > >         private bool _isExecutable;
> > >         private bool _isRam;
> > >         private IList<CMSTransientFileInstance> _fileInstances = new
> > > List<CMSTransientFileInstance>();
> > >         private IList<CMSTransientCategory> _categories;
> > >         private IList<CMSTransientPackage> _packages;
> >
> > >         [Property(ColumnType="Boolean")]
> > >         public virtual bool IsExecutable {
> > >             get {return this._isExecutable;}
> > >                                                 set{this._isExecutable
> = value;}
> > >         }
> >
> > >         [Property(ColumnType="Boolean")]
> > >         public virtual bool IsRam {
> > >             get {return this._isRam;}
> > >                                                 set{this._isRam =
> value;}
> > >         }
> >
> > >         [HasMany(typeof(CMSTransientFileInstance), Lazy=true)]
> > >         public virtual IList<CMSTransientFileInstance> FileInstances {
> > >             get {return this._fileInstances;}
> > >                                                 set{this._fileInstances
> = value;}
> > >         }
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientCategory),
> > > ColumnRef="CategoryId", ColumnKey="ApplicationId",
> > > Table="Applications2Categories")]
> > >         public virtual IList<CMSTransientCategory> Categories {
> > >             get {return this._categories;}
> > >                                                 set{this._categories =
> value;}
> > >         }
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientPackage),
> > > ColumnRef="PackageId", ColumnKey="ApplicationId",
> > > Table="Applications2Packages")]
> > >         public virtual IList<CMSTransientPackage> Packages {
> > >             get {return this._packages;}
> > >                                                 set{this._packages =
> value;}
> > >         }
> > >     }
> >
> > >     [ActiveRecord()]
> > >     public partial class CMSTransientFileInstance :
> > > ActiveRecordBase<CMSTransientFileInstance> {
> >
> > >         private int _id;
> > >         private string _name;
> > >         private CMSTransientContentType _contentType;
> > >         private CMSTransientApplication _application;
> > >         private CMSTransientFileInformation _fileInformation;
> > >         private IList<CMSTransientOperativeSystem> _operativeSystems;
> >
> > >         [PrimaryKey(PrimaryKeyType.Native, ColumnType="Int32")]
> > >         public virtual int Id {
> > >             get {return this._id;}
> > >                                                 set{this._id = value;}
> > >         }
> >
> > >         [Property(ColumnType="String")]
> > >         public virtual string Name {
> > >             get {return this._name;}
> > >                                                 set{this._name =
> value;}
> > >         }
> >
> > >         [BelongsTo("ContentTypeId")]
> > >         public virtual CMSTransientContentType ContentType {
> > >             get {return this._contentType;}
> > >                                                 set{this._contentType =
> value; }
> > >         }
> >
> > >         [BelongsTo("ApplicationId", NotNull=true)]
> > >         public virtual CMSTransientApplication Application {
> > >             get {return this._application;}
> > >                                                 set{this._application =
> value;}
> > >         }
> >
> > >         [BelongsTo("FileInformationId")]
> > >         public virtual CMSTransientFileInformation FileInformation {
> > >             get {return this._fileInformation;}
> > >
> set{this._fileInformation = value;}
> > >         }
> >
> > >         [HasAndBelongsToMany(typeof(CMSTransientOperativeSystem),
> > > ColumnRef="OperativeSystemId", ColumnKey="FileId", Lazy=true,
> > > Table="Files2OperativeSystems")]
> > >         public virtual IList<CMSTransientOperativeSystem>
> > > OperativeSystems {
> > >             get {return this._operativeSystems;}
> > >
> set{this._operativeSystems = value; }
> > >         }
> > >     }
> >
> > >     [ActiveRecord()]
> > >     public partial class CMSTransientContentType :
> > > ActiveRecordBase<CMSTransientContentType> {
> >
> > >         private int _id;
> > >         private string _name;
> > >         private string _mIMEType;
> > >         private IList<CMSTransientFileInstance> _files = new
> > > List<CMSTransientFileInstance>();
> >
> > >         [PrimaryKey(PrimaryKeyType.Native, ColumnType="Int32")]
> > >         public virtual int Id {
> > >             get {return this._id;}
> > >                                                 set{this._id = value;}
> > >         }
> >
> > >         [Property("Description", ColumnType="String", NotNull=true)]
> > >         public virtual string Name {
> > >             get {return this._name;}
> > >                                                 set{this._name =
> value;}
> > >         }
> >
> > >
> >
> > ...
> >
> > read more ยป
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to