1

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?

senzacionale
  • 20,448
  • 67
  • 204
  • 316

2 Answers2

1

I don't know the problem, but here is how I would debug it:

  1. Check that it is saved correctly in the database. Check that the relationships are there.
  2. Turn on SQL output as per here
  3. Check what SQL your query generates. Try running the SQL yourself.
  4. Change the mapping or query using intuition.
  5. Try writing the query in other ways, say using nHibernate.LINQ.

nHibernate does not cache queries unless you tell it to.

Community
  • 1
  • 1
Iain
  • 10,814
  • 3
  • 36
  • 31
  • 1
    +1 for excellent debug steps. I've found that steps 2 and 3 are *always* so useful that I leave SQL logging on by default on all my projects during development. – Ragesh Jan 03 '11 at 04:38
  • @Ragesh - wow, careful if you are pushing binary blobs to the database, it will actually hex encode and log the full binary payload – fostandy Jan 03 '11 at 23:52
  • @fostandy, That's a good point. Personally, I've never run into that problem as I try really hard to keep blobs away from the DB. And, of course, I keep the logging turned up only during development. – Ragesh Jan 04 '11 at 18:52
0

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

Baz1nga
  • 15,485
  • 3
  • 35
  • 61