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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Delete Record using Linq 3
Linq. Count. 3
XML and SQL database 3
Linq. Select 1
LINQ - Select records 3
Linq. Why do I get this error? 4
Linq.How to complete this query? 2
Filter 1

Back
Top