从数据库读取时的 nhibernate 会话问题
我使用 nhibernate 在数据库中提交一些数据。
TimeSlices newTimeSlices = new TimeSlices(timeSliceStartTime, timeSliceEndTime, schedule, newScheduleDay);
tsDao.Save(newTimeSlices);
tsDao.CommitChanges();
但后来我尝试读取这些数据
public ScheduleDays GetByDate(DateTime date, Schedules schedule)
{
NHibernateSession.Refresh(schedule);
DateTime tmpDate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
return NHibernateSession.CreateCriteria(typeof (ScheduleDays))
.Add(Restrictions.Eq(ScheduleDaysProperties.Date.ToString(), tmpDate))
.Add(Restrictions.Eq(ScheduleDaysProperties.Schedule.ToString(), schedule))
.UniqueResult<ScheduleDays>();
}
但没有成功。我查看数据库,它就在那里,但我无法从数据库中读取它。我如何刷新会话或者我必须做什么才能在保存后读取这些新数据。问题仅出现在我使用 ajax 组件时。
public ScheduleDaysMap()
{
Id(x => x.ScheduleDayId);
Map(x => x.Date)
.Not.Nullable();
Map(x => x.MinutesOrderInterval)
.Not.Nullable();
References(x => x.Schedule)
.Column(TableNames.ScheduleId)
.Not.Nullable()
.LazyLoad();
HasMany(x => x.Orders)
.KeyColumn(TableNames.ScheduleDayId)
.Inverse()
.LazyLoad()
.AsBag();
HasMany(x => x.TimeSlices)
.KeyColumn(TableNames.ScheduleDayId)
.Inverse()
.LazyLoad()
.AsBag();
Version(x => x.Timestamp);
}
timeSliceStartTime、timeSliceEndTime 和 newTimeSlices 是 od 类型 DateTime
Schedule 是 DB 对象类型(表 Schedules)
newScheduleDay 是 DB 对象类型(表 ScheduleDays)
我正在使用 C# + 流畅的 nhibernate 1.1
映射和延迟加载或 asbag 可能有问题吗?或者可能出了什么问题?
I commit some data in DB with nhibernate.
TimeSlices newTimeSlices = new TimeSlices(timeSliceStartTime, timeSliceEndTime, schedule, newScheduleDay);
tsDao.Save(newTimeSlices);
tsDao.CommitChanges();
but then i try to read this data
public ScheduleDays GetByDate(DateTime date, Schedules schedule)
{
NHibernateSession.Refresh(schedule);
DateTime tmpDate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
return NHibernateSession.CreateCriteria(typeof (ScheduleDays))
.Add(Restrictions.Eq(ScheduleDaysProperties.Date.ToString(), tmpDate))
.Add(Restrictions.Eq(ScheduleDaysProperties.Schedule.ToString(), schedule))
.UniqueResult<ScheduleDays>();
}
but without succeed. I look in DB and it is there but i can not read it from DB. How can i refresh session or what i must do that i can read this new data after i save it. Problem is only when i am working with ajax components.
public ScheduleDaysMap()
{
Id(x => x.ScheduleDayId);
Map(x => x.Date)
.Not.Nullable();
Map(x => x.MinutesOrderInterval)
.Not.Nullable();
References(x => x.Schedule)
.Column(TableNames.ScheduleId)
.Not.Nullable()
.LazyLoad();
HasMany(x => x.Orders)
.KeyColumn(TableNames.ScheduleDayId)
.Inverse()
.LazyLoad()
.AsBag();
HasMany(x => x.TimeSlices)
.KeyColumn(TableNames.ScheduleDayId)
.Inverse()
.LazyLoad()
.AsBag();
Version(x => x.Timestamp);
}
timeSliceStartTime, timeSliceEndTime and newTimeSlices are type od DateTime
schedule is DB object type (Table Schedules)
newScheduleDay is DB object type (Table ScheduleDays)
I am using C# + fluent nhibernate 1.1
Can be problem with mapping and lazy load or asbag? Or what can be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道问题所在,但这是我调试它的方法:
nHibernate 不会缓存查询,除非您告诉它。
I don't know the problem, but here is how I would debug it:
nHibernate does not cache queries unless you tell it to.
嘿,你可以运行 nhibernate profiler 并查看正在触发什么查询吗?相同的链接是 nhprof.com
Google 看看如何使用 nhprof 它非常简单。
希望有帮助
Hey Can you run nhibernate profiler and see what query is getting fired. The link to the same is nhprof.com
Google to see how to use nhprof its very simple.
Hope that helps