Copyright © 2008 ASC Associates, Technical Support support@ascassociates.biz , Sales Enquiries sales@ascassociates.biz
Choosing a SQLDataSource, LINQDataSource or EntityDataSource (updated 17th November 2009)

When you create an interface using a Visual Studio WebForms, you have the choice of several controls through which a user will interact with the data. We support the four most popular controls; FormView, ListView, GridView and DetailsView.

The example below shows a FormView control. Associated with each user interface control is a DataSource control, which links the interface control to the source of data. In the example below an EntityDataSource is being used.



As a developer you have three possible choices for the type of datasource control to use.

This article looks at the implications for developers in making a choice between using one of the three different types of Data Sources in Visual Studio. We hope this information may help you in coming to a decision over using a particular type of data control. All three of the control types can be used to both directly update data in tables and update data in views (subject to certain restrictions imposed in views).

SQLDataSource

This is the oldest technology of the three and has the advantage of simplicity of use for people whom are adept at SQL. The control has separate SQL commands for inserting, deleting and updating data.

If you are not fluent in writing SQL then you will find that you need to get up to speed with SQL to make best use of the control.

SQLDataSource -Advantages
SQLDatasource – Disadvantages
LINQDataSource

This data source is a step down the road in taking away a lot of the technical detail behind making the mechanics of updating data work and freeing up the developer to focus on more application related issues.

In order to use LINQ you need to either use an external program called SQLMetal (supplied with Visual Studio or a better choice is to use the Free utility SQL Metal Builder which provides a more friendly interface for running SQLMetal which is a command line program), or a manual process to create a dbml file in your VS web site. The dbml file is a roadmap of all your tables and views in the application and contains a lot of clever technology that enables LINQ to offer certain advantages over the SQLDataSource.

LINQDataSource – Advantages
LINQDataSource – Disadvantages

The most significant problem in the above is the first point which relates to null values in date and numeric fields, this can be resolved by ensuring these fields always have values and updating existing data. This problem is no longer an issue with an EntityDataSource.

One other point to consider is the lack of support for the automatic updating of the dbml file. However, using manual techniques new tables and views can be quite easily dragged and dropped onto the dbml layout, and existing tables removed and added back to reflect structural changes.

EntityDataSource

The very latest choice of technology is the EntityDataSource, which extends the approach taken with the LINQDataSource by adding further capabilities.

EntityDataSource – Advantages

The newest type of Data Source has most of the advantages of LINQ and offers additional features.

EntityDataSource – Disadvantages
Summary

If you don’t already have a good reason for choosing a type of datasource and you are willing to learn a little C# style syntax then our recommendation would be to use the EntityDataSource. If you are a hardened SQL fan, and want to explicitly use SQL Server specific functions outside of encapsulating them in views then the older SQLDataSource maybe a better choice.

But remember, you can also mix the use of different DataSources in your WebForms, using the most appropriate choice for the task in-hand.

MUST+WEB converting Access Databases to .net with Visual Studio. Click below to improve your development productivity.

by Andrew Couch Office Access MVP, Director ASC Associates andy@ascassociates.biz



Copyright © 2008 ASC Associates, Technical Support support@ascassociates.biz , Sales Enquiries sales@ascassociates.biz