Skip to content

Codepolice

  • ⤫

Create a tag cloud with a limited amount of tags in ASP.NET and LINQ

Posted by Judy Alvarez Posted on February 25, 2022March 1, 2022
0

Today I built a Tag cloud for my new site. I found this great article about how to do it with LINQ and C#. But I missed some features. Especially how to limit the number of tags that were shown. So if you read that article and then have a look at this code if you have the same problem as me.

var tagSummary = (from ti in db.TagItemRelations
	group ti by ti.Tag.Text into tagGroup
	select new {
	Tag = tagGroup.Key,
	TagFrequency = tagGroup.Count()
}).OrderByDescending(x=>x.TagFrequency).Take(20);

int maxTagFrequency = (from t in tagSummary select t.TagFrequency).Max();

var tagCloud = (from ti in tagSummary
	select new TagCloudItem {
	Tag = ti.Tag,
	Weight = (double)ti.TagFrequency / maxTagFrequency * 100
}).OrderBy(x=>x.Tag);

The main difference between my code and the code in the article is that I have a slightly more complex data model (should not matter) and that I make the second query against the “result” from the first query. This allows me to first order by popularity and then in alphabetic order.

Please leave a comment if there is any better way to do this or if you have any questions.

Categories: JavascriptTagged: asp . net interview questions, asp .net core, asp dot net, asp net 5, asp net ajax, asp net boilerplate, asp net cache, asp net caching, asp net core 5.0, asp net core webapi, asp net dropdownlist, asp net identity, asp net mvc 5, asp net nedir, asp net session management, asp net vs php, asp net web api interview questions, asp net webforms, asp net zero, asp. net, connection string in asp net, cookies asp net, framework asp net, interview questions on asp net, is asp net a framework, php vs asp net, query string in asp net, web services in asp net, what is asp net mvc

Post navigation

Previous Previous post: ASP.NET 4.0 – Some info from PDC
Next Next post: Using JQuery Validation plugin with ASP.NET

Related Posts

  • Bringing Python apps into Node

    #​596 — October 14, 2025 Read on the Web 📂 A Modern Guide to Reading and Writing Files in Node — A comprehensive guide to various methods for working with files, from promise-based methods through to working with streams, processing files concurrently, using file handles, and memory-efficient techniques. Luciano Mammino A Way to Integrate Python ASGI with Node.js

    Posted by Posted on October 14, 2025
    0
  • Vite gets its own documentary

    #​756 — October 10, 2025 Read on the Web JavaScript Weekly ▶  Vite: The Documentary — From the same creators of the fantastic ▶️ Node.js, ▶️ Angular and ▶️ React documentaries comes an up to date look at Vite, the build tool that has taken the JavaScript ecosystem by storm in recent years. Many luminaries make an appearance to

    Posted by Posted on October 10, 2025
    0
  • npm security best practices to consider

    #​595 — October 7, 2025 Read on the Web 15 Recent Node Features That Can Replace Popular npm Packages — Many features that once required third-party packages are now built into the runtime itself. Here’s a look at some of the most notable that you may want to experiment with, prior to reducing unnecessary dependencies. Lizz

    Posted by Posted on October 7, 2025
    0
  • React 19.2 is in the building

    #​755 — October 3, 2025 Read on the Web JavaScript Weekly The State of JavaScript 2025 Survey — Each year, Devographics runs an epic survey of as many JavaScript community members as it can and turns the results into an interesting report on the state of the ecosystem – here’s the results from 2024. If

    Posted by Posted on October 3, 2025
    0
  • Using Node with Cloudflare Workers

    #​594 — September 30, 2025 Read on the Web 🗓️ We’re back after taking a week off for my birthday. I’ve never bothered to do that before, but I figured I’d give it a go, and.. it was good 😅 We’re now back every week until Christmas!__Peter Cooper, your editor A Year of Improving Node.js

    Posted by Posted on September 30, 2025
    0
  • The first browser with JavaScript landed 30 years ago

    #​754 — September 26, 2025 Read on the Web JavaScript Weekly Give Your AI Eyes: Introducing Chrome DevTools MCP — The Chrome team has released an MCP server for Chrome DevTools, enabling agents like Claude Code or OpenAI Codex to use the DevTools to debug and analyze the performance and behavior of your webapps (or

    Posted by Posted on September 26, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • Bringing Python apps into Node
  • Vite gets its own documentary
  • npm security best practices to consider
  • React 19.2 is in the building
  • Using Node with Cloudflare Workers
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice