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.
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
then building this table is nothing else than iterating over your m:n table
EquipmentAtLocationand writingQuantityinto 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.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.