Hi,
Having a few problems with nHibernate, thought I'd check I'm not being an idiot before delving deeper into the problem.
I have two objects a Page and a Schedule which are related in a 1:1 manner. Page has a Schedule_Id field which related to the Id on the Schedule table. The Page object has a Schedule object set up as a property. However, many objects in my data scheme can have a Schedule - not just a Page.
In the Page mapping file I have this line:
References(Function(x) x.Schedule).ForeignKey("Schedule_Id").Cascade.All()
However in the Schedule map, there's no references set up, and the Id is declared as an Id:
Id(Function(x) x.Id)
Now this relationship doesn't seem to be working properly. If I try and load page objects after setting up an Alias like this:
Dim session As ISession = NHibernateSessionManagerStore.Instance.GetSession()
results = session.CreateCriteria(Of DataTransferObjects.Page)() _
.CreateAlias("Schedule", "schedule", SqlCommand.JoinType.LeftOuterJoin) _
.Add(Expression.Like("Category", catToSearch)) _
.List(Of DataTransferObjects.Page)()
The expression works fine (filtering on category) but the pages returned have nonsense schedule objects which aren't properly populated and certainly don't contain the data I was expecting.
Have I set up my mappings correctly? Do I need to change the Schedule mapping as well to ensure it references the relationship to the Page object correctly, and if so how do I do it to ensure that Schedules can key in to other data objects as well?
Cheers, Matt