The diffrence between [ActiveRecord("`Order`")] and [ActiveRecord("Order")]

2 views
Skip to first unread message

Tony.Chen

unread,
May 27, 2008, 6:04:26 AM5/27/08
to Castle Project Users
[ActiveRecord("`Order`")]
public class Order : ActiveRecordBase
{
private int id;
private DateTime createdAt;
private DateTime? dispatchedAt;
private Customer customer;
private OrderStatus status;
private float total;
private ISet<Product> products = new HashedSet<Product>(); ......


Generally,We just write class like this:
[ActiveRecord(DiscriminatorValue="firm")]

I really don't konw the diffrence between [ActiveRecord("`Order`")]
and [ActiveRecord("Order")]

tks

Ben Lovell

unread,
May 27, 2008, 6:09:34 AM5/27/08
to castle-pro...@googlegroups.com
The one with the backticks ensures that the table name is escaped (for the DB dialect chosen) when it appears in queries.

Ayende Rahien

unread,
May 27, 2008, 6:09:55 AM5/27/08
to castle-pro...@googlegroups.com
Order is a keyword, so you need to quote that
` is the quote character for NH

Jimmy Shimizu

unread,
May 27, 2008, 6:14:18 AM5/27/08
to castle-pro...@googlegroups.com
AFAIK the difference is that using backticks (`) will make the generated
query sanitized for specific reserved words that usually aren't allowed
as table/column-names.

So I would say that it's good practise to always backtick (newer
releases of the DB-engine might add new reserved words in the future).

/Jimmy

Tony.Chen

unread,
May 27, 2008, 10:12:13 PM5/27/08
to Castle Project Users
Thanks, I have to consider carefully

Dennis

unread,
Jun 2, 2008, 6:02:43 AM6/2/08
to Castle Project Users
Why isn't it the default behavior? In almost all cases you would be
interested in your database table names that reuse a database keyword
just works when you map it with activerecord.

On May 27, 5:09 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> Order is a keyword, so you need to quote that
> ` is the quote character for NH
>

Ken Egozi

unread,
Jun 2, 2008, 6:06:11 AM6/2/08
to castle-pro...@googlegroups.com
it's a matter of taste I think.

I wouldn't like to see the generated sql all clattered with [] signs.
--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.musicglue.com
http://www.castleproject.org
http://www.mamaherb.com
http://www.gotfriends.co.il

Jakob Tikjøb Andersen

unread,
Jun 2, 2008, 8:52:09 AM6/2/08
to castle-pro...@googlegroups.com
It could implemented as a configuration setting in nHibernate to always escape table and columnnames. But then again, many queries are unreadable as it is....

Ayende Rahien

unread,
Jun 2, 2008, 9:40:57 AM6/2/08
to castle-pro...@googlegroups.com
Case sensitivity in some DB.


On Mon, Jun 2, 2008 at 1:02 PM, Dennis <da...@davh.dk> wrote:

Ayende Rahien

unread,
Jun 2, 2008, 9:41:14 AM6/2/08
to castle-pro...@googlegroups.com
Take a look at INamingStrategy
Reply all
Reply to author
Forward
0 new messages