Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:23:44+00:00 2026-05-23T22:23:44+00:00

I am working on an asp.net mvc3 application with linq2sql. I have a List

  • 0

I am working on an asp.net mvc3 application with linq2sql.

I have a List of SiteLog object type containing also for each object: A string named CLRExceptionType and a date named EntryDate. This List is included in a Dictionary:

private Dictionary<string, List<SiteLog>> dataBaseList = new Dictionary<string, List<SiteLog>>();
DataClasses1DataContext db = new DataClasses1DataContext("string1");
DataClasses1DataContext db2 = new DataClasses1DataContext("string2");

And I populate the vocabulary in the same controller in a function:

       private void CreateDictionary()
    {   
        dataBaseList.Add("db", db.SiteLogs.ToList());
        dataBaseList.Add("db2", db2.SiteLogs.ToList());
    }

So for each “Database” I have a list of Exception occurred.

Now I have to display on the view, for each database, the exception occurred grouped by exception and ordered by date.

So for example the output will be: Database1:
Exception1 (22 times) last occurred: 22.10.1989 19:30
Exception2 (2 times) last occurredd 20.5.1980 14.50

Then suddenly the object is updated with a new entry with the name Exception2 so I have to display:
Exception2 (3 times) last occurredd 20.7.2011 9:00
Exception1 (22 times) last occurred: 22.10.1989 19:30

How can I achieve this using the groupby or any other solution in the controller?
I return the dictionary to the view.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:23:45+00:00Added an answer on May 23, 2026 at 10:23 pm

    Try this:

    var result =
      dataBaseList.GroupBy(x => x.Key)
                  .SelectMany(x =>
                                x.SelectMany(n => n.Value
                                                   .GroupBy(g => g.CLRExceptionType)
                                                   .Select(g => new
                                                                {
                                                                  DB = x.Key,
                                                                  Exception = g.Key,
                                                                  Count = g.Count(), 
                                                                  LastOccured = 
                                                                   g.Max(y =>
                                                                         y.EntryDate)
                                                                })))
                  .OrderBy(x => x.DB)
                  .ThenByDescending(x => x.LastOccured);
    

    This groups your dictionary by the key (= database). Each group is then grouped by the exception type. For each such group an anonymous type is selected with all the data you want to display. SelectMany flattens the data from an IEnumerable<IEnumerable<T>> to an IEnumerable<T>. The result is then ordered by the database and then by the last occurred date.
    The result will be a list of anonymous type instance, each with the info you want to display.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on asp.net MVC3 application and I have created a layout.cshtml which
I have Ninject working nicely in an ASP.NET MVC3 web application. I'd like to
I have working application in asp.net MVC3. Today when I was working on it
I had a simple working (ASP.NET) Scenario here: 3 asp:RadioButtons that each have OnCheckedChanged
I am working on a project which adopted ASP.NET MVC3(Razor) tech. Now, I have
I am working on an ASP.Net MVC3 application and I'm having trouble understanding the
I have the following WebGrid in my ASP.NET MVC3 test application. It displays a
I have a webpage I am working on using asp.net mvc3. I am deploying
I'm working with an ASP.net MVC3.0 application and I keep Current User information in
I'm working on a web application project using ASP.NET MVC3 and database in SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.