Simple implementation of instance demo by using LINQ to access

Source: Internet
Author: User

The question obtained through the previous article: Is LINQ to access required for website development? Is it true that a third-party class library is used to implement LINQ to access, such as alinq, dblinq, and iqtoolkit? Can I use my own method to extend the LINQ method? Do I have to use the LINQ tracking method?

Your own answer: LINQ to access is not only to save SQL space, but also to develop simple websites. For example, on a general enterprise site, SQL database is not required. Access is simple and easy to back up. There are still a lot of websites that use access for databases, especially those developed by ASP. Basically, access is the primary database. Access can still be one of the databases we need to select during development. Using the method of LINQ to access not only can access the ACCESS database, but also needs to change the connection string of the database to achieve seamless Implementation of LINQ to SQL. In this way, you can select the database you want to use based on your website. This method is also relatively simple, only generated according toCodeThe file *. Designer. CS can be perfectly implemented by slightly modifying a few places. If you use LINQ, you don't need to learn anything new to use an Access database for implementing LINQ. Now there are other methods to implement LINQ to access, such as alinq, dblinq, and iqtoolkit. However, none of the official products provided by Microsoft can be used easily by using LINQ to SQL. Using a simple modification to the LINQ to SQL to implement the LINQ to access method is not a good method, and it does not increase the time to learn new class libraries. We can also implement the database processing method by extending the datacontext class. For example, you can add, delete, or update your own data. The primary key cannot be used for search and deletion. In reality, many methods are used. We can extend these methods. Submitchanges () is required for implementing the LINQ trace. If you want to write your own database operations, you do not need to trace them. I think this is also good for performance.

The main changes made by LINQ to SQL are as follows:
1. In the definitionPublic Partial ClassDbgame: Add Property Control provider to system. Data. LINQ. datacontext, [provider (Typeof(System. Data. LINQ. sqlclient. sql2000provider)] to implement the default sql2000provider. If this parameter is not added, the default value is
Sql2008provider, I do not know first ().
2. modify [Table (name = "DBO. table Name ")] changed to [Table (name =" table name ")] to remove DBO. because access does not support adding DBO to the table.
Otherwise, the DBO table cannot be found.

Because this method is used, submitchanges () cannot update the database, so you must write the update method update yourself <t> (t ), it updates the modified object based on the primary key. I also hope someone can help me to update the database through submitchanges. After a simple test, other functions that can be implemented in LINQ to SQL are also supported. We also hope you can help us find other compatibility issues.Download the source code of the LINQ to access demo.

Discussion: How can I update the database using access data through submitchanges ()? Can I use access in a small project? Can I use a better method to implement LINQ to access.


 

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.