I don't need to add any methods, map any parameters, or write any code for the to handle both these querying and updating scenarios - it can work against the LINQ to SQL data model we point it against and do these operations automatically.When updates are made, the LINQ to SQL ORM will automatically ensure that all business rules and validation logic we've added (as partial methods) to the LINQ to SQL data model pass before persisting anything to the database.But to begin with we'll just use the above data model as-is to build our UI. NET page with a control to bind the Grid View to our data model.VS 2008 includes build-in designer support to make it easy to connect up our Grid View (or any other ASP. To bind our grid above to the data model we created earlier, we can switch into design-view, select the Grid View, and then select the "New Data Source..." option within the "Choose Data Source:" drop-down: This will bring up a dialog box that lists the available datasource options to create.
For example, we could remove the "Quantity Per Unit" column below and re-run our application to get this slightly cleaner UI: If you have used the control before and explicitly passed update parameters to update methods (the default when using Data Set based Table Adapters) one of the things you know can be painful is that you have to change the method signatures of your Table Adapter's update methods when the parameters based by your UI are modified.
Below are the first four parts of my LINQ to SQL series: control that is shipping as part of ASP. All of the business rules and business validation logic will be implemented in our data model tier - and within the UI tier or in any of the UI pages.
This will ensure that: 1) a consistent set of business rules are used everywhere within the application, 2) we write less code and don't repeat ourselves, and 3) we can easily modify/adapt our business rules at a later date and not have to update them in dozens of different places across our application.
You can always write custom UI code to directly work against your LINQ to SQL data model if you prefer, or when you find a UI scenario that isn't particularly suited to using the control to build the web application scenario I defined above.
We'll begin working on the application by first defining the data model we'll use to represent our database.