-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with lazy loaded property
PostPosted: Mon Mar 14, 2011 4:48 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
Hi,

I have a problem that the lazy loaded property does not get loaded by the query and does not on the first access either. As the first case looks correct as the property is lazy, the second seems to be some problem to me (as it should initialize the property by a roundtrip to the database, according to what Ayende wrote here http://ayende.com/Blog/archive/2010/01/ ... rties.aspx)

In more details, I have a class Customer and I map it with fluent api. The database gets configured in the following way:

Code:
private static ISessionFactory CreateSessionFactory()
{
   var csb = new System.Data.SqlServerCe.SqlCeConnectionStringBuilder("data source=data.sdf");
   var ds = csb.DataSource;
   var engine = new System.Data.SqlServerCe.SqlCeEngine(csb.ConnectionString);

   if (!File.Exists(csb.DataSource))
   {
      engine.CreateDatabase();
   }

   var interceptor = new DataBindingIntercepter();

   var sessionFactory = Fluently.Configure()
      .Database(MsSqlCeConfiguration.Standard
         .ConnectionString(csb.ConnectionString)
         .ShowSql()
         // .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
         // .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu")
         .CurrentSessionContext("thread_static"))
      .Mappings(m => m.FluentMappings.AddFromAssemblyOf<CustomerMap>())
      .ExposeConfiguration(x =>
      {
         // Add INotifyPropertyChanged interface with an interceptor...
         x.SetInterceptor(interceptor);
         new SchemaExport(x).Create(false, true);
      })
      .BuildSessionFactory();

   interceptor.SessionFactory = sessionFactory;

   engine.Shrink();

   return sessionFactory;
}


The Customer class has one lazy property - Data. It is mapped fluentlu as: Map(x => x.Data).CustomType("StringClob").LazyLoad();

All is wired by WindsorContainer. And the following code seems to work incorrectly to me:

Code:
using (var session = container.Resolve<ISessionFactory>().OpenSession())
{
   var item = session.CreateQuery("from Customer")
      .SetMaxResults(1)
      .UniqueResult<Customer>();
   var data = item.Data;
}


...as the data variable is null whereas the database contains data there.

The question is how to properly handle lazy properties once having an object got from the query (I use LINQ)...

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: Re: Problem with lazy loaded property
PostPosted: Thu Mar 17, 2011 6:32 am 
Newbie

Joined: Thu Mar 17, 2011 6:28 am
Posts: 1
The film was remade into Tamil,Telugu and Kannada and Babu Antony portrayed his character in all the four languages,which might be a record held only by him.













famous actors from countries lists


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.