views:

753

answers:

1

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.

+3  A: 
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.

Mauricio Scheffer
is "where" in your translation simply "pAppIdentifier"?
Ash
Actually, what i mean to ask - is it:session.Delete(string.Format("from {0} where AppIdentifier='{1}'", type.Name, pAppIdentifier));
Ash
exactly like that.
Mauricio Scheffer