Entity Framework beginners (1)-Model Creation

Source: Internet
Author: User
Tags management studio sql server management sql server management studio sql server express

Entity Framework is an ORM (object relational mapping object ing) solution provided by Microsoft for free. it not only helps us solve the problem of data caching, but also implements completely object-oriented programming with minimal overhead. It is a well-being of agile development in small and medium-sized projects. As a newbie, the blogger was lucky enough to participate in the development of several projects using Entity Framework (hereinafter referred to as ef). Although during the development of these projects, A lot of detours have taken place, and the information on the Internet is not complete. After a year of experience, I have gained some experience. So from today on, I want to share these little experiences with you on my blog.

Based on the actual needs of project development, this series of tutorials will not repeat EF's internal mechanism too much to help you build your own data layer from scratch.

If there are any errors in this article, I hope the old birds can correct them. I have a better idea for the implementation in this article, and you are welcome to discuss it with me at any time. My mailbox: [email protected]

I. Development Preparation

Microsoft integrated EF as early as vs2008 SP1. However, earlier versions are not very convenient to use. We recommend that you use Visual Studio of vs2012 or later for EF development. In this article, I will use the development environment vs 2012 + SQL Server express 2012 for actual operations.

As a tool for data persistence, EF supports three generation modes: database first (database first), model first (model first), and code first (code first, data-driven, model-driven, and interactive (Action)-driven applications. This article uses a relatively simple and easy-to-understand database priority model.

 

Database priority mode. As the name implies, you must first have a database. We open SQL Server Management studio and create a new database named House, which contains two main tables, house and seller. the table structure is as follows:

 

After the meeting, we can officially enter the development stage. The blogger's vs2012 comes with ef5.0. Don't worry if the partner's vs version does not provide the EF module. Download one from Microsoft's official nuget. The specific steps are as follows:

1. Open your project.

2. Choose tools> nuget package management> Manage nuget packages of the Solution

3. Search for and install Entity Framework

2. Establish a data model

After the installation is complete, create an EF model in the project. The specific steps are as follows:

After that, if you are prompted that the file is insecure, it is because the. CS file is automatically generated by EF and can be ignored directly. Do not forget to save after generation.

After the model is successfully saved, the first EF model is created.

 

Entity Framework beginners (1)-Model Creation

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.