I have been searching far and wide and seem to find many examples that are "close" to what I need, but not exactly.
To keep it simple, I have this:
Class Article
Key ID
Property int Views
List<KeywordInstance> KeywordInstances
Class KeywordInstance
Key ID
Property Article InstanceArticle
Property Keyword Keyword
Property int Weight
Class Keyword
Key ID
List<KeywordInstance> KeywordInstances
Again, over simplified, but I have articles, and I have keywords. Then there is a link table that maps articles to keywords (many to many) with a weight (i.e. frequency the keyword appears in the article).
I have two-way navigation. An article should give me its list of keywords that I will sort by weight, and a keyword should give me its list of articles that I can also sort by weight.
These are my mapping tables (simplified for space, the key parts I believe are there)
<class
name="Article"
lazy="true">
<id
name="ID"
>
<generator
class="native"/>
</id>
<property name="views"/>
<set
name="KeywordInstances"
cascade="all"
inverse="true"
>
<key
column="ArticleID"/>
<one-to-many class="KeywordInstance"/>
</set>
</class>
<class
name="Keyword"
lazy="true"
>
<id
name="ID"
<generator
class="native"/>
</id>
<set
name="KeywordInstances"
cascade="all"
inverse="true"
>
<key
column="KeywordID"/>
<one-to-many class="KeywordInstance"/>
</set>
</class>
<class
name="KeywordInstance"
lazy="true"
>
<id
name="ID"
>
<generator
class="native"/>
</id>
<property
name="Weight"/>
<many-to-one
name="InstanceArticle"
column="ArticleID"
class="Article"
cascade="none"
not-null="true"/>
<many-to-one
name="InstanceKeyword"
column="KeywordID"
class="Keyword"
cascade="none"
not-null="true"/>
</class>
The typical cycle is to pull in an article, roll through it's keywords to generate the meta-tags, and then update a "view count" - literally, something like this:
Article article = _session.Select(typeof(article),key);
foreach(keywordinstance key in article.keywordinstances)
{
// do something with key.InstanceKeyword.KeywordValue
}
article.Views++
_session.flush();
The problem that I'm having is that a simple display of a single page suddenly graphs for me hundreds of select statements over keyword, even if it only has two keywords.
I very this with the profiler. Any thoughts on where I might be going wrong?
|