Reputation: 1364
I am getting this error while creating SessionFactory. Here is the code, if some can check this out.
class NHibernateHelper {
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory {
get {
if (_sessionFactory == null) {
InitializeSessionFactory();
}
return _sessionFactory;
}
}
private static void InitializeSessionFactory() {
_sessionFactory = Fluently.Configure().
Database(MsSqlConfiguration.MsSql2008.ConnectionString
("Server=tcp:z4m56fgh.database.windows.net,1433;Database=db;User ID=user;Password=xxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;").
ShowSql()).
Mappings(m => m.FluentMappings.AddFromAssemblyOf<House>()).
ExposeConfiguration(cfg => new SchemaExport(cfg).Create(false, true)).
BuildSessionFactory();
}
public static ISession OpenSession() {
return SessionFactory.OpenSession();
}
}
Mappings:
public class HouseMap : ClassMap<House> {
public HouseMap() {
Id(x => x.Id);
References(x => x.Owner).Cascade.All();
References(x => x.Rooms).Cascade.All();
References(x => x.Consumptions).Cascade.All();
}
}
public class ConsumptionMap : ClassMap<Consumption> {
public ConsumptionMap() {
Id(x => x.Id);
Map(x => x.Type);
Map(x => x.AvgDay);
Map(x => x.AvgMonth);
Map(x => x.AvgYear);
}
}
public class RoomMap : ClassMap<Room> {
public RoomMap() {
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Number);
Component<TemperatureData>(x => x.TemperatureData,
t => {
t.Map(x => x.TemperatureCurrent, "Current");
t.Map(x => x.TemperatureSet, "Set");
});
Component<RoomFeatures>(x => x.Features,
f => {
f.Map(x => x.Shutters, "ShuttersUp");
f.Map(x => x.Lights, "LightsOn");
});
}
}
This exact class NHibernateHelper works with another Model, so it must be something wrong with my mappings. Also, it still does not work if i exclude everything from HouseMap, i.e. comment on the References.
Upvotes: 0
Views: 3939
Reputation: 96
It is being a little difficult to realize what is the source of your problem without the classes, although, a guess would be at the Consumptions property. If it is a list (as it seems by its name) it should be mapped with HasMany instead of References.
Besides, maybe you could attach the stack trace with the InnerException. This could give us a clue.
Upvotes: 1