This project is read-only.
Required References

the project requires the following references

Change set 93158 supports NH 3.1 required references
NHibernate 3.1

Change set 93166 supports NH 3.2 required references
NHibernate 3.2 + (using Nuget, as Remotion.Linq is included in the NH dll)

Expression<Func<Person, bool>> where = p => p.FirstName == "James";
int executeCommand = session.Update<Person>(where)
    .Set(x => x.Age, 123) //set new value
    .Set(x => x.LastName, "Prime")

Expression<Func<LogEntry, bool>> where = x => x.DateTime > DateTime.Now.AddHours(-1);
int updatedEntityCount = session.Delete<LogEntry>(where).ExecuteCommand();

joins cannot be used directly with DML, however they can be used in a sub query, small example:
to apply an update to all the people who live in Oxford.
Expression<Func<Person, bool>> where = x => x.Address.City == "Oxford";
int updatedEntityCount = session.Update<Person>(where)
    .Set(x=>x.FirstName, "Bob")

This works by creating the required sub query. thus updating all the Person objects with an address in oxford

There are 2 main functions,

ExecuteCommand - executes the command against the session

GenerateCommand - This will generate the HQL and return it as a string
Expression<Func<Person, bool>> where = x => x.Address.City == "Oxford";
string hqlCommand = session.Update<Person>(where)
    .Set(x=>x.FirstName, "Bob")

Last edited Oct 1, 2011 at 5:07 PM by dbones, version 2


No comments yet.