Distinct

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have three tables:
Articles > ArticleId, Title, ...
Tags > TagId, Name
ArticlesTags > ArticleId, TagId

Tags also relate to other tables, like documents, through
DocumentsTags ...

I am trying to get how many Tags are related to Articles:
ArticlesTagsCount = database.ArticlesTags.Distinct().Count(),

The problem is that I have 3 tags and this gives me 4 ...
.... I think I am getting the number of times the tags are used in
Articles and not the number of tags associated to articles ...

Do you understand?

How can I fix this?

Note: I have all table relationships well defined.

Thanks,
Miguel
 
shapper said:
Hello,

I have three tables:
Articles > ArticleId, Title, ...
Tags > TagId, Name
ArticlesTags > ArticleId, TagId

Tags also relate to other tables, like documents, through
DocumentsTags ...

I am trying to get how many Tags are related to Articles:
ArticlesTagsCount = database.ArticlesTags.Distinct().Count(),

You want to select just the TagId column from ArticlesTags before calling
Distinct(), so that it returns just unique tags and not all unique (article,
tag) pairs.
 
Back
Top