views:

23

answers:

1

So I've been using Castle ActiveRecord for my latest project and for the most part I like it a lot. Now I'm trying to figure out how to execute a simple join query with AR and I'm not seeing it.

So I have an Article table and an article could have many tags associated to it. This is the attribute in the Article class:

[HasAndBelongsToMany(typeof(Tag), Table="ArticleTags", ColumnKey="ArticleID", ColumnRef="TagID")]
    public IList<Tag> Tags {
            get
            {
                return m_tagList;
            }
            set
            {
                m_tagList = value;
            }
    }

There's a Tag class that contains the name and ID of the tag. There's the required bridge/association table which AR can handle without an explicit class.

So now I just want to get all articles that have a given tag name. Thus far, I haven't figured how to do that in AR. The SQL is easy. Trying to reproduce for AR, not so much.

Any help here would be much appreciated.

A: 

Well, shortly after posting this, I found my answer.

I used a DetachCriteria object and then put that into my Article.SlicedFindAll() function.

Here's the code.

DetachedCriteria query = DetachedCriteria.For<Article>()
            .CreateCriteria("Tags")
                .Add(Expression.Eq("Name", tag));

Spent all afternoon on this. sigh

KeithA