Note that there are some explanatory texts on larger screens.

plurals
  1. POFiltering data with MVC3 and ADO.NET Entity Data Models
    primarykey
    data
    text
    <p>I've created a table called Orders in my SQL Server 2008 db. This table has columns which include dateCreated of type Date, CustomerId, InvoiceTypeId, InvoiceId etc. I also have Invoice, Customer and InvoiceType tables.</p> <p>I've created a View in my database where I join all these tables together, selecting only the few columns I'm interested in.</p> <p>In my MVC3 Visual Studio project I've created a ADO.NET Entity Data Model to represent the db view. I've also created a very simple controller. Finally I created a razor view with a WebGrid to display my orders. It works fine.</p> <p>Is this a approach reasonable?</p> <p>Lets say I now wish to add to my razor page the ability to add a start date and a end date which can be used to filter the contents of the WebGrid, how might I do this?</p> <p>I'm guessing there are two ways of doing this.</p> <ol> <li><p>Load all the data from the db view into the entity model. Then the filtering code would be added perhaps in the razor code. The db should not need to be read each time the filter is changed since all the data is already in the model.</p></li> <li><p>add to the db view some extra sql code, something like <strong>WHERE (dateCreated BETWEEN @StartDate AND @EndDate)</strong> and then have the model read from the db each time we change the filter. This would be good if there are a large amount of records in the Orders table and we are normally only interested in viewing perhaps the last week or few days. Is this possible to do with the MVC3 approach? How can it be done?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload