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)...