Search Results

Search found 5 results on 1 pages for 'mcardinale'.

Page 1/1 | 1 

  • How to fix a NHibernate lazy loading error "no session or session was closed"?

    - by MCardinale
    I'm developing a website with ASP.NET MVC, NHibernate and Fluent Hibernate and getting the error "no session or session was closed" when I try to access a child object. These are my domain classes: public class ImageGallery { public virtual int Id { get; set; } public virtual string Title { get; set; } public virtual IList<Image> Images { get; set; } } public class Image { public virtual int Id { get; set; } public virtual ImageGallery ImageGallery { get; set; } public virtual string File { get; set; } } These are my maps: public class ImageGalleryMap:ClassMap<ImageGallery> { public ImageGalleryMap() { Id(x => x.Id); Map(x => x.Title); HasMany(x => x.Images); } } public class ImageMap:ClassMap<Image> { public ImageMap() { Id(x => x.Id); References(x => x.ImageGallery); Map(x => x.File); } } And this is my Session Factory helper class: public class NHibernateSessionFactory { private static ISessionFactory _sessionFactory; private static ISessionFactory SessionFactory { get { if(_sessionFactory == null) { _sessionFactory = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(MyConnString)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ImageGalleryMap>()) .ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none")) .BuildSessionFactory(); } return _sessionFactory; } } public static ISession OpenSession() { return SessionFactory.OpenSession(); } } Everything works fine, when I get ImageGallery from database using this code: IImageGalleryRepository igr = new ImageGalleryRepository(); ImageGallery ig = igr.GetById(1); But, when I try to access the Image child object with this code string imageFile = ig.Images[1].File; I get this error: Initializing[Entities.ImageGallery#1]-failed to lazily initialize a collection of role: Entities.ImageGallery.Images, no session or session was closed Someone know how can I fix this? Thank you very much!

    Read the article

  • How implement the Open Session in View pattern in NHibernate?

    - by MCardinale
    I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with lazy loading. Through this question (http://stackoverflow.com/questions/2519964/how-to-fix-a-nhibernate-lazy-loading-error-no-session-or-session-was-closed), I've discovered that I have to implement the Open Session in View pattern , but I don't know how. In my repositories classes, I use methods like this public ImageGallery GetById(int id) { using(ISession session = NHibernateSessionFactory.OpenSession()) { return session.Get<ImageGallery>(id); } } public void Add(ImageGallery imageGallery) { using(ISession session = NHibernateSessionFactory.OpenSession()) { using(ITransaction transaction = session.BeginTransaction()) { session.Save(imageGallery); transaction.Commit(); } } } And this is my Session Factory helper class: public class NHibernateSessionFactory { private static ISessionFactory _sessionFactory; private static ISessionFactory SessionFactory { get { if(_sessionFactory == null) { _sessionFactory = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(MyConnString)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ImageGalleryMap>()) .ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none")) .BuildSessionFactory(); } return _sessionFactory; } } public static ISession OpenSession() { return SessionFactory.OpenSession(); } } Someone could help me to implements Open Session in View pattern? Thank you.

    Read the article

  • How to configure a URL with 3 levels in ASP.NET MVC?

    - by MCardinale
    Using ASP.NET MVC, I need to configure my URLs like this: www.foo.com/company : render View Company www.foo.com/company/about : render View Company www.foo.com/company/about/mission : render View Mission If "company" is my controller and "about" is my action, what should be "mission"? For every "folder" (company, about and mission) I have to render a different View. Anyone knows how can I do that? Thanks!

    Read the article

1