Search code examples
.netcastle-activerecord

Help with a Castle Active Record DeleteAll HQL String


So I basically want to have a static method in my AR class to delete all records on a specified expression. But apparently Castle Active Record doesnt have an overload for IQuery params (at least not the version I am using).

This is what I am "effectively" trying to acheive:

public static void Delete(string pAppIdentifier) {
  DeleteAll(new EqExpression("AppIdentifier", pAppIdentifier));
}

It is possible to use HQL (as one of the overloads for DeleteAll allows a where HQL string, but I really dont yet fully understand HQL and all its power and I was hoping one of my Stack Overflow peers could help me turn that example above into HQL.


Solution

  • DeleteAll(string.Format("AppIdentifier='{0}'", pAppIdentifier))
    

    this is translated into:

    session.Delete(string.Format("from {0} where {1}", type.Name, where));
    

    BTW make sure that the pAppIdentifier parameter is safe, otherwise you'll have a potential SQL injection vulnerability.

    This and other common questions in the ActiveRecord wiki.