Modeling ASP. Petapoco for an existing database

Source: Internet
Author: User

Preface: Recently has been seizing the company's website, not a lot of time to write a blog, accumulated a lot of problems, almost a day, tossing and dying, especially in the model of several setbacks.

In the past, most of the PHP development, rarely touched the model (thinkphp model), but in C # and Java Web Development, MVC model became an essential piece, in ASP. NET, a lot of data model, view model.

By the way the data model +orm, you can quickly implement the mapping, what is a mapping? In short: Abstract the data table into an object-oriented language, and then through the CRUD implementation of the object to the database crud (crud: Delete and change)

The underlying model class in thinkphp is the Think\model class, which accomplishes basic curd, activerecord patterns, coherent operations, and statistical queries, and some advanced features are encapsulated in another model extension.

The design of the base model class is very flexible, and even without any model definition, the ORM and curd operations of the related data tables can be performed, and the model class must be defined only when it is necessary to encapsulate separate business logic.

1. Introduction: Petapoco is a C # Micro ORM Framework, basically no configuration, only composed of a single CS file, support. net3.5. net4.0. The official also produced a matching T4 template to automatically generate the database models. Official website: http://www.toptensoftware.com/petapoco/, the latest official version of Petapoco at the time of the deadline is 5.0.1.

2. Download: Open vs, Right-click on Project-"Manage NuGet Packages"-"Find download installation Petapoco

3. Configuration: NuGet After installing Petapoco two more things: Petapoco.cs and generated directory, open Generated/database.tt, this is a T4 template, you can automatically generate C # code, modified as follows:

" Sunjob "  "sunjob.models""Sunjobrepo";

Modify the database name (the Name property of the connection string under Web. config), namespace, and then right-click on the saved TT file-"Run the custom tool, one more Database.cs is the model of the current database to be built

Open the Database.cs to understand, there is a database of the model, including tables and views, if the table is found in front of "dbo." or missing the view chart, indicating that this petapoco may have a problem, please note, please see my other article "SQL Server under the brackets and dbo prefix."

You can use this mini ORM framework in your own project below!

Modeling ASP. Petapoco for an existing database

Related Article

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.