tags:

views:

87

answers:

2

Hi,

I am in a situation where I want to return a list of article objects. The properties of Article object looks as follows.

private int _articleId;

private string _articleName;

private List<Tag> _tags;

Now as you can see the article object has a property called _tags which is a list of type "Tag". Now assuming that I want to return a list of Article objects, how can i populate this list of type Tags when I am returning the list of Article objects.

I am looking to display the result as follows:

ArticleName 

Tag1 Tag2 Tag3
A: 

Get the list of Articles.

Then use a SQL query to get the list of Tags (assuming the resulting data has some sort of identifier as to what article it applies to.

Loop over these tags and build the lists for the correct Articles accordingly.

ghills
This may not always be preferable since you will do a call for each article. Suppose you have 10000 articles, that's an extra 10000 DB calls. *shudder* (of course, paging will help)
Adrian Godong
Or you could use Lazy Loading: http://en.wikipedia.org/wiki/Lazy_loading
Burnsys
I didn't mean to query for each article. If you do one query to get all the tags (for all articles), you can then associated tags with articles. Thats why I said it is important for the Tags query to pull some sort of identifier for the article it applies to.
ghills
A: 

This is the sort of thing I would employ Hibernate or NHibernate for.

This answer actually provides a great leg up.

Kevin

related questions