NHibernate / Fluent NHibernate
Where Clause in Many-to-Many relationship
Filter results based on child property value using lambda expression
public class UserOverrides : IAutoMappingOverride<User>
{
public void Override(AutoMapping<User> mapping)
{
mapping.HasManyToMany(x => x.Accounts)
.Table("UserAccounts")
.ChildWhere(x => x.IsActive);
}
}
Generic DeleteAll method to delete all records of a specific type
public class Repository<T> : IRepository<T>
{
public void DeleteAll()
{
SessionProvider.GetCurrentSession().CreateQuery("DELETE FROM " + typeof(T).ToString()).ExecuteUpdate();
}
}