How do I delete an object without fetching it from the db first?
In another ORM, I can do this:
session.Delete<User>(1); // 1 = PK
Add the following class to your project:
public static class SessionHelper
{
public static void Delete<TEntity>(this ISession session, object id)
{
var queryString = string.Format("delete {0} where id = :id",
typeof(TEntity));
session.CreateQuery(queryString)
.SetParameter("id", id)
.ExecuteUpdate();
}
}
You can now use session.Delete<User>(1)
.
You could do this
User user = new User();
user.Id = 1;
session.Delete(user);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With