I've been thinking about how NHibernate doesn't yet easily support bulk operations on entities and I think this is something that many of us could really use.
This might not be the correct forum, but I wanted to propose some ideas to maybe get people thinking about this and hopefully inspire us to patch or provide extension points to support this.
Right now, we have DetachedCriteria which gives us a rich API we can use to describe the WHERE clause of a SELECT.
We could leverage that existing logic to drive the WHERE clauses of DELETES and UPDATES.
For example:
Code:
DeleteCriteria delete = DeleteCriteria.For(typeof(SomeEntity)) // DELETE FROM SomeEntity s
.Add(Expression.Eq("SomeProperty", someValue)); // WHERE s.SomeProperty = someValue
UpdateCriteria update = UpdateCriteria.For(typeof(SomeEntity)) // UPDATE SomeEntity s
.Add(Update.SetProperty("PropertyName", newValue)) // SET s.PropertyName = newValue
.Add(Update.CopyProperty("Destination", "Source")) // ,s.Destination = s.Source
.Add(Update.Numeric("NumericProperty", n, Numeric.Add) // ,s.NumericProperty = s.NumericProperty + n
.Add(Update.Numeric("NumericProperty", n, Numeric.Subtract) // ,s.NumericProperty = s.NumericProperty - n
.Add(Update.Numeric("NumericProperty", n, Numeric.Multiply) // ,s.NumericProperty = s.NumericProperty * n
.Add(Update.Numeric("NumericProperty", n, Numeric.Divide) // ,s.NumericProperty = s.NumericProperty / n
.Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Add) // ,s.Numeric1 = s.Numeric1 + s.Numeric2
.Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Subtract) // ,s.Numeric1 = s.Numeric1 - s.Numeric2
.Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Multiply) // ,s.Numeric1 = s.Numeric1 * s.Numeric2
.Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Divide) // ,s.Numeric1 = s.Numeric1 / s.Numeric2
.Add(Expression.Eq("SomeProperty", someValue)); // WHERE s.SomeProperty = someValue
I really don't want to have to write SQL to do these types of things when NHibernate already has knowledge about my model.
Does anyone else think this is worthwhile? What other things can we add to this? How do we go about working on this if it is worthwhile?