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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:27:24+00:00 2026-05-26T08:27:24+00:00

I have developed a system for a client using ASP.Net MVC 3 and Entity

  • 0

I have developed a system for a client using ASP.Net MVC 3 and Entity Framework 4. The system is a small application which lets the client record and monitor his equipment, ie, he can add a piece of equipment such as a PC (record the Asset Number, Price, Warrenty Expires etc), assign it to a Category (ie PC System, Printer, Speaker etc) and also record the location of the equipment (ie Main Office, Store Room, 2nd Building). This all works fine, however, recently the client has asked for some reports to be built into the system.

Some reports are simple to do, ie, search by equipment asset number and then return all the additional info related to that. However, there is one report which he needs, this is to list all the Locations at the top of the report and then all the Categories at the left of the report just like a grid/ lookup table. Then this will show the total number of equipment categories in each location, for example, the total number of PC Systems at 2nd Building, total number of Speakers in the Store Room etc.

I was thinking, although I could be wrong, that this is not what Entity Framework was designed for, ie, returning objects, not datasets displaying calculations. Therefore, I was wondering, what would be the best way to do this?

I was thinking of possibly using Microsoft Enterprise Library and Stored Procedures to just return a dataset of results, however, maybe this is the wrong approach?

Again, any feedback would be much appreciated and I apologise if my request is a bit confusing.

Thanks.

  • 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-26T08:27:25+00:00Added an answer on May 26, 2026 at 8:27 am

    What your customer wants you to show is called a pivot table. Take a look at the answer here: Pivot table in c# entity framework.

    But if you have the following entities

    public class Location {
       public int LocationId { get; set; } // PK
    }
    public class Equipment {
       public int EquipmentId { get; set; } // PK
    }
    public class EquipmentAtLocation {
       public int LocationId { get; set; } // PK/FK
       public int EquipmentId { get; set; } // PK/FK
       public int Quantity { get; set; }
    }
    

    then building this table is nothing else than iterating over your m:n table EquipmentAtLocation and writing Quantity into the cell that is given by LocationId and EquipmentId. If you don’t have that PK on that table, then you need to do a grouping by LocationId and EquipmentId on that table first.

    var locations = ctx.Locations.Select((val, idx) => new { val.LocationId, idx }).ToDictionary(x => x.LocationId, y => y.idx); // get a map of location to index
    var equipments = ctx.Equipments.Select((val, idx) => new { val.EquipmentId, idx }).ToDictionary(x => x.EquipmentId, y => y.idx); // get a map of equipment to index
    
    int[,] pivot = new int[locations.Count, equipments.Count];
    foreach (var entry in ctx.EquipmentAtLocations) {
      pivot[locations[entry.LocationId], equipments[entry.EquipmentId]] += entry.Quantity;
    }
    

    I don’t know if the data contract serializer is able to serialize multidimensional arrays, otherwise you have to use a jagged array. You should of course pack that into an object and also include the header information (the keys in the dictionary when ordered by value) so that you know which index means what.

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

Sidebar

Related Questions

I have developed a C# 3.5 Mvc 1.0 application using oracle 11gR2 client which
i have developed an application in which i fetch books using googleapibook search. I
I'm currently working on an Intranet application project, using ASP.NET MVC 3. One of
I have developed a small C# form application which calls a web service. Everything
I have developed a build system on MSBuild (NET 3.0) and cc.net to perform
I have developed a small download system in PHP, where files are downloaded through
I have an internal enterprise application I've developed for my company built on .Net
I have problems during serialization/deserialization. I'm using a WCF service (that used .NET framework)
I have an existing asp.net application that is currently in production for more than
I have developed a small server that recives connections (using basically the example here:

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.