2-1. Creating a simple model using the graphical interface designer to create an easy

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

First, create a new project

Second, add model files

After adding, right-click in the design panel blank and create an entity

Entity set (B) Here the name will be the corresponding database table name!!! , at first don't know what this is, after the creation of the table name is this, after the attention point on the line.

Iv. Adding an entity scalar attribute (scalar property)

You have now completed a simple conceptual model. There is still something to be done to generate the database from the model.

Five, you have now completed a simple conceptual model. There is still something to be done to generate the database from the model.

1, right click on the design interface blank, select Properties, modify the database framework name is CHAPTER2, modify the entity container named Recipe1context

2. Generate database from model, right click Design interface to generate database based on model

Select the server where you want to create the database, and the name of the database you want to create, where the database name is named: ef6recipes

Select the database you just created

Select EF Version

The EF tool generates SQL scripts based on the model you just created

When you click Done, vs default Opens the script you just generated, click the Execute button to create the table structure

Open SQL Server Management Studio to view the database that has been built

Vi. operation model: inserting, retrieving data

Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks;  Namespace consoleapplication3{class Program {static void Main (string[] args) {using (var context = new Recipe1context ()) {var person = new Person {FirstName = "Robert", MiddleName =                "Allen", LastName = "Doe", PhoneNumber = "867-5309"}; Context.                Personset.add (person);                person = new Person {FirstName = "John", MiddleName = "K.", LastName = "Smith", PhoneNumber = "867-5309"}; Context.                Personset.add (person);                person = new Person {FirstName = "Kathy", MiddleName = "Anne", LastName = "Ryan", PhoneNumber = "867-5309"}; Context.                Personset.add (person); Context.            SaveChanges (); } using (var context = new Recipe1context ()) {foreach (var in context).           Personset) {         Console.WriteLine ("{0} {1} {2}, Phone: {3}", person.) FirstName, person. MiddleName, person. LastName, person.                PhoneNumber);            } console.readkey (); }        }    }}

Run the output result:

To view database records:

2-1. Creating a simple model using the graphical interface designer to create an easy

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.