Joined: Fri Jun 08, 2007 5:21 am Posts: 2
|
I have mapped classes User and Division
Division has this mapping
<bag name="Users" inverse="true">
<key column="Division" />
<one-to-many class="User"/>
</bag>
And user has this
<many-to-one name="Division"/>
Then if i do following under same transaction/session even if i commit transaction it doesn't work.
Division division = new Division();
division.Name = "First";
session.Save(division);
User user = new User("nobody");
user.Division = division;
session.Save(user);
IList<Division> divisions = session.CreateCriteria(typeof(Division)).List<Division>();
foreach (Division div in divisions)
{
Console.WriteLine("Division - Name: " + div.Name);
foreach (User user in div.Users)
{
Console.WriteLine("Division User - Id: " + user.Id + " User: " + user.DisplayName);
}
}
No users are found....wierd....
But if i do this under that previous foreach users are returned.
IList<User> users = session.CreateCriteria(typeof(User))
.Add(Expression.Eq("Division", div))
.List<User>();
Until i close my current session i don't get any users from division. After closing session and opening new one and new transaction it works just fine. Is it a bug or am i doing something wrong?
|
|