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