nhibernate / fluent-nhibernate

Fluent NHibernate!
BSD 3-Clause "New" or "Revised" License
1.66k stars 686 forks source link

PersistenceSpecification CheckList fails on Many-to-Many relationship #59

Open jagregory opened 13 years ago

jagregory commented 13 years ago

It seems that CheckList enforces ordering on the lists that it checks. I have a many-to-many relationship between Users and Roles as follows:

public UserMap()
{
  Id(x => x.Id);
  Map(x => x.UserName);
  Map(x => x.Email);
  HasManyToMany(x => x.Roles)
      .Access.CamelCaseField()
      .Inverse();
}

public RoleMap()
{
  Id(x => x.Id);
  Map(x => x.Name);
  HasManyToMany(x => x.Users)
      .Access.CamelCaseField();
}

My testing is as follows:

/* Create test Users list */
new PersistenceSpecification<Role>(session)
  .CheckProperty(u => u.Name)
  .CheckList(u => u.Users, users, (role, user) => role.AddUser(user))
  .VerifyTheMappings();

Sometimes this fails and sometimes it passes. From some debugging, it seems that it is retrieving the Users in a different order than which they were added. I imagine it because the generated Guid (using Guid.Comb) is altering the order on the database query. (I think it is because the guid is not sequential on the association table.) So basically, even though the list contains the same elements, since they are in a different order, fails the test because the source appears to compare elements by index position. So my question is, should I be enforcing an order on my queries or should CheckList not assume ordering on the list?

icambron commented 13 years ago

I'd modify CheckList() to be indifferent about the order. OTOH, I'm sometimes forced to add ordering in situations like this to fix paging (my database server is sometimes not even consistent about the order of results on a query against the the same data).

leandrosa commented 7 years ago

This issue is opened yet. Does exist some answer for this question? Cause I having this same problem.