Some small suggestions for strongly typed datasets

Source: Internet
Author: User

A strongly typed dataset can help us quickly build the data access layer, and its simplicity allows us to use it extensively in small projects. But it also has some minor flaws, and here is a discussion of what the flaws are and how we can avoid them.

1 in a query, it only supports operations on this table and does not support operations on multiple tables. In this case, we can write a stored procedure ourselves and create a new TableAdapter so that it will help us generate a new logical entity table that stores the columns returned in the stored procedure.

2 Any changes on the database side will not automatically update to a strongly typed DataSet. This feature may be resolved in later versions, and in Orcas, strongly typed Datasets and LINQ still do not have the capability to automatically update the schema. Since it does not automatically update the schema, we can only manually delete the table and then add the table again (manually changing the properties of the field is OK, but it is easy to cause errors). In this case, all written query will be lost. To avoid this, we can write all of the query as a stored procedure so that we can easily add it again even if the table is deleted.

3 The strongly typed dataset has a problem getting the return value of the stored procedure (e.g. returns 1). We can't conveniently get int returnvalue = (int) da as a function. CALLSP (); To get its return value, we need to implement a generated TableAdapter partial class, and then add this custom method:

Code

Partial class Userstableadapter
{Public
object Getreturnvalue (int commandindex) {return this
. Commandcollection[commandindex]. Parameters[0].   Value;
}
}

The value of this commandindex is the index of your method, in the following example, Index is 1 (index is starting from 0):

Now we can get the return value by using the following code:

Code

Da. CALLSP (xx, xx);
int returnvalue = Int. Parse (DA. Getreturnvalue (2). ToString ());

Of course, in the orcas, we also have a better choice, it is to use Linq-sql. It is. NET's ORM tool, it can automatically generate SQL scripts for you through LINQ query, allowing you to quickly build the data access layer, the support is more powerful. However, in the. NET Framework 3.5 SP1, it will be replaced by linq-entity.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.