Waqar, Fabio answered in a humorous way, but he's right :-)

The "in" clause in HQL maps to the "in" clause in SQL, and you need
parenthesis surrounding the list of values.
Keep in mind you could have used a literal instead of a bound parameter:

  delete from MyEntity where EntityId in (343, 23487, 8263)

The above clause is both valid HQL and SQL.

   Diego


On Fri, Dec 18, 2009 at 00:48, Fabio Maulo <[email protected]> wrote:

> really NH is great!!
> It allow people to work with RDBMS without know SQL.
>
> 2009/12/18 Waqar Sadiq <[email protected]>
>
> I apalolgize.  It was my mistake that I had mis-spelled EntityId.  It
>> is all good.
>>
>> I di dwant to ask about the syntax though.  What is with the
>> parenthesis around :keys.  In all my previous queries where I specify
>> a bound parameter, I never put parenthesis.
>>
>> Thanks.
>>
>> On Dec 17, 9:18 pm, Waqar Sadiq <[email protected]> wrote:
>> > That worked and I advanced to the nest step.
>> >
>> > After creating the query, I set the bound parameter and then execute
>> > the query.
>> >
>> > IQuery query = session.CreateQuery("delete from MyEntity where
>> > EntityId in (:keys)");  // The type of EntityId is long.
>> > query = query.SetParameterList("keys", keys); // the type of keys is
>> > long[]
>> > int nRows = query.ExecuteUpdate();
>> >
>> > I get the following error at the ExecuteUpdate().
>> >
>> > "Can't determine SqlType of parameter name=keys_0_,
>> > expectedType=Unknow
>> >  Possible cause: wrong case-sensitive property-name."
>> >
>> > Thanks.
>> >
>> > On Dec 17, 7:34 pm, Diego Mijelshon <[email protected]> wrote:
>> >
>> >
>> >
>> > > where EntityId in (:keys)
>> >
>> > >    Diego
>> >
>> > > On Thu, Dec 17, 2009 at 21:35, Waqar Sadiq <[email protected]>
>> wrote:
>> > > > I think I spoke too soon.  I get the following error:
>> >
>> > > > NHibernate.Hql.Ast.ANTLR.QuerySyntaxException : Exception of type
>> > > > 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column
>> > > > 86 [delete from MyNamespace.MyEntity where EntityId in :keys]
>> >
>> > > > I get this on the line
>> >
>> > > > session.CreateQuery("delete from MyEntity where EntityId in :keys");
>> >
>> > > > Any ideas.
>> >
>> > > > Thanks.
>> >
>> > > > Waqar
>> >
>> > > > On Dec 15, 8:06 am, Waqar Sadiq <[email protected]> wrote:
>> > > > > We are not really mapping associations so the cascade strategy is
>> not
>> > > > > very helpful to me in this particular case.  The above discussed
>> query
>> > > > > seems to eb workign for me.
>> >
>> > > > > On Dec 14, 3:46 pm, Jason Meckley <[email protected]> wrote:
>> >
>> > > > > > like Diego said, there isn't really a "best" way. How you go
>> about
>> > > > > > deleting depends on your mappings. the cascade strategy you use
>> will
>> > > > > > greatly influence how you delete data. I have heard of some
>> systems
>> > > > > > that do not require the use of Save or Delete. All inserts and
>> deletes
>> > > > > > are managed by Adding or Removing an object from a collection.
>> >
>> > > > > > On Dec 14, 4:13 pm, Diego Mijelshon <[email protected]>
>> wrote:
>> >
>> > > > > > > I don't know if there's a "best" way, but that query is pretty
>> > > > efficient if
>> > > > > > > you already have the keys.
>> >
>> > > > > > > The usage is:
>> >
>> > > > > > > session.CreateQuery("delete MyEntity where id in :keys")
>> > > > > > > .SetParameterList("keys", keys)
>> > > > > > > .ExecuteUpdate();
>> >
>> > > > > > >    Diego
>> >
>> > > > > > > On Mon, Dec 14, 2009 at 17:53, Waqar Sadiq <
>> [email protected]>
>> > > > wrote:
>> > > > > > > > Hi All,
>> >
>> > > > > > > > I need to delete a bunch of objects that belong to a set.
>>  In my
>> > > > case
>> > > > > > > > these objects have primay key of type Int64.  I have an
>> array if
>> > > > Int64
>> > > > > > > > containing the keys of objects that I need to delete.  What
>> would
>> > > > be
>> > > > > > > > the best way of deleting them.
>> >
>> > > > > > > > Ideally, I would be able to write a query like this:
>>  (Ignoring
>> > > > > > > > transactions)
>> >
>> > > > > > > > Int64[] keys = ...;  // an array of primary keys.
>> >
>> > > > > > > > string queryStr = "delete from MyEntity wher MyKey in
>> :keys";
>> > > > > > > > IQuery query = Session.CreateQuery(queryStr);
>> > > > > > > > query.ExecuteUpdate();
>> >
>> > > > > > > > Is this the correct way to delete objects from a set?
>> >
>> > > > > > > > Any help would be appreciated.
>> >
>> > > > > > > > --
>> >
>> > > > > > > > You received this message because you are subscribed to the
>> Google
>> > > > Groups
>> > > > > > > > "nhusers" group.
>> > > > > > > > To post to this group, send email to
>> [email protected].
>> > > > > > > > To unsubscribe from this group, send email to
>> > > > > > > > [email protected]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> ­­>
>> > > > <nhusers%[email protected]<nhusers%[email protected]>
>> <nhusers%252bunsubscr...@googlegroup­­s.com>
>> > > > ­­>
>> > > > > > > > .
>> > > > > > > > For more options, visit this group at
>> > > > > > > >http://groups.google.com/group/nhusers?hl=en.-Hidequotedtext-
>> >
>> > > > > > - Show quoted text -- Hide quoted text -
>> >
>> > > > > - Show quoted text -
>> >
>> > > > --
>> >
>> > > > You received this message because you are subscribed to the Google
>> Groups
>> > > > "nhusers" group.
>> > > > To post to this group, send email to [email protected].
>> > > > To unsubscribe from this group, send email to
>> > > > [email protected]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> ­­>
>> > > > .
>> > > > For more options, visit this group at
>> > > >http://groups.google.com/group/nhusers?hl=en.-Hide quoted text -
>> >
>> > > - Show quoted text -- Hide quoted text -
>> >
>> > - Show quoted text -
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>>
>>
>
>
> --
> Fabio Maulo
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to