Created
March 6, 2013 15:52
-
-
Save chilversc/5100296 to your computer and use it in GitHub Desktop.
NHibernate Contains query bug - mutating a collection after a query has executed breaks queries in subsequent sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void UsersWithListContains_MutatingListDoesNotBreakOtherSessions() | |
{ | |
using (var firstSession = OpenSession ()) { | |
var names = new List<string> { "ayende", "rahien" }; | |
var query = (from user in firstSession.Query<User> () | |
where names.Contains(user.Name) | |
select user).ToList(); | |
names.Clear (); | |
Assert.AreEqual(2, query.Count); | |
} | |
using (var secondSession = OpenSession ()) { | |
var names = new List<string> { "ayende" }; | |
var query = (from user in secondSession.Query<User> () | |
where names.Contains(user.Name) | |
select user).ToList(); | |
// This line fails with Expected: 1 But was: 0 | |
// The SQL in NHProf shows that the where clause was executed as WHERE 1 = 0 as if names were empty | |
Assert.AreEqual(1, query.Count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The bug is caused by line 11,
names.Clear()