Data Grid in MVC 3

Jul 11, 2011 at 8:22 AM
Edited Jul 11, 2011 at 3:38 PM

Hey Hi !

I am converting one asp.net web form site to asp.net mvc3.

The web based forms is using Data Grid to manipulate Data and sets the Data Source attribute to Data Table.

I am getting the data from stored procedure using entity framework.It would be very kind of you if you can suggest me how to go about the same.

I have gone through your tutorials But in my case the scenario is little bit different.

To accomplish a single task i am calling various Stored Procedure.

Will it be a good practise to create one model comprising of all the Details required at View End and instanciating with the values coming from Stored Procedure.

Coordinator
Jul 11, 2011 at 5:27 PM

If you use EF4 you get .Net objects as result of procedure execution. You can put various results of your stored procedures into different properties of the ViewModel. It is better to translate the various objects into other simple objects when data reach the controller, because data retrurned by EF may cause problems in Views. You can accomplish this with AutoMapper for instance.

 

Retrieving data with stored procedures has the disadvantage that the stored procedures doesn't return IQueryables but norma IEnumerable, so you can not manipulate effivciently them to do filtering, or sorting. If you use normal queryes than applying to them filetering or sorting expressions, LinQ put this expressions together to issue an unique query to the DB. This means, you can filter data in the business layer or in the controller ...Notwithstanding this filtering is done by the database not in memory. 

In case you use stored procedure, you can't apply sorting or filtering lambda expressions returned by some grid directly to the results returned by the stored proedure, but you have to sinspect them and use them to pass the right parameters to your stored procedures.

Usually, I consider stored procedures just to do updates, or to retrieve single values. 

 

Hope what I have said might help. I can say more because what you ask is quite vague.

 

About the tutorials: they are simple because their purpose is to make the reader understand some concept, thus one tries to avoid complications that might take the reader far from the focus of the tutorial. However, this doesn't mean you can't do more complex things...putting together different pieces :)