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 6690525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:38:50+00:00 2026-05-26T05:38:50+00:00

i am doing mvc3 and linQ i have the database like this class student

  • 0

i am doing mvc3 and linQ
i have the database like this

class    student        gender

A        john           Male
B        George         Male
A        bill           Female
A        Steve          Male

how do i code to filter the duplicate as the result as below

A
John       male
bill       female
steve      male

B
George     male

i have tried method A

  var bb = from bbb in unitOfWork.Checklists
                     orderby bbb.class
                     select bbb;

and also method B

        var group = (from p in unitOfWork.Checklists
                     group p by p.class into g
                     select new Checklists
                     {
                         class= g.Key,
                          name= g.ToString()
                     }).AsEnumerable();

but all failed~
Any idea for this ? This is breaking my head!

  • 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-26T05:38:51+00:00Added an answer on May 26, 2026 at 5:38 am

    try to use ObjectDumper project in the visual studio C# sample

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace testLinq
    {
        public class Record
        {
            public string ClassName {get;set;}
            public string Student {get;set;}
            public string Gender {get;set;}
    
    
        }
    
        class Program
        {
            public static void Main(string[] args)
            {
                Console.WriteLine("Hello World!");
    
                Record[] list = new Record[] { 
                    new Record { ClassName="A" , Student="john" , Gender="male" },
                    new Record { ClassName="B" , Student="George" , Gender="male" },
                    new Record { ClassName="A" , Student="bill" , Gender="Female" },
                    new Record { ClassName="A" , Student="Steve" , Gender="male" }
                };
    
                var result = list.GroupBy(x => x.ClassName).Select(x => new { k = x.Key, person = x});
    
                ObjectDumper.Write(result, 1);
    
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey(true);
            }
        }
    }
    

    The output is

    Hello World!
    k=A     person=...
      person: ClassName=A     Student=john    Gender=male
      person: ClassName=A     Student=bill    Gender=Female
      person: ClassName=A     Student=Steve   Gender=male
    k=B     person=...
      person: ClassName=B     Student=George  Gender=male
    Press any key to continue . . .
    

    Example MVC code

    public class YourViewModel
    {
        public YourViewModel()
        {
            Record[] list = new Record[] { 
                new Record { ClassName="A" , Student="john" , Gender="male" },
                new Record { ClassName="B" , Student="George" , Gender="male" },
                new Record { ClassName="A" , Student="bill" , Gender="Female" },
                new Record { ClassName="A" , Student="Steve" , Gender="male" }
            };
    
            var result = list.GroupBy(x => x.ClassName).Select(x => new { k = x.Key, person = x});
            using (var writer = new StringWriter())
            {
                ObjectDumper.Write(result, 1 , writer);
                pivotString = writer.ToString();
            }
        }
    
        private string pivotString;
    
        public string PivotTableText { get { return pivotString; } }
    }
    
    public static class YourHtmlExtension
    {
        public static string EncodedMultiLineText(this HtmlHelper helper, string text) 
        {
          if (String.IsNullOrEmpty(text)) 
          {
            return String.Empty;
          }
          return Regex.Replace(helper.Encode(text), Environment.NewLine, "<br/>")
        }
    }
    

    In your controller

        public ActionResult ReadPivotTable()
        {
            return View((new YourViewModel());
        }
    

    In your view

    <%= Html.EncodedMultiLineText(Model.PivotTableText) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a RESTful API that we are doing in MVC3. We would like
If I had a model like this in my MVC3 application: public class Person
When doing TDD , how to tell that's enough tests for this class /
I have an MVC3 application doing AJAX edit of a grid line using JQUERY
I'm learning ASP.NET MVC3 and doing an application with CMS capabilities - but have
Using MVC3, I have a Student Repository (in a project) and a StudentService (in
I have picked LINQ to SQL as ORM framework for ASP .NET MVC3 project.
I have default routes from mvc3 like {root}/account/details/123 and I want - {root}/a/123 I
I have a page in MVC3 with a model of pageModel. In this page
I'm confused by this behavior: I have an out-of-the-box MVC3 app. I haven't really

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.