EF is further encapsulated on the basis of ADO, and if I do new projects later I might consider using EF instead of ADO.
Actually a long time ago I had contact with EF, but too long useless, some forget, a few days ago, also made a little notes. The records are as follows:
1. How to create EF No, look at the XML file that opened EF after EF was created.
First right, select Open with XML text
After folding, the SSDL content here defines the database fields in SQL Server.
The CSDL content defines the property fields of the class
CS MAPPING defines a mapping between a database field and a class's attribute field
2. Take a look at the TT template
Before EF has no TT template, now added, if you understand the source code, you can modify the rules of his codes, but the general situation does not have to modify it.
The ModelGuestBook.Context.tt suffix here is the code that generates the object interface.
The modelguestbook.tt suffix here is the code that generates the Model class.
3. Take a look at the database connection string generated by EF
<add name= "ccxdemoentities" connectionstring= "metadata=res://*/modelguestbook.csdl|res://*/ Modelguestbook.ssdl|res://*/modelguestbook.msl;provider=system.data.sqlclient;provider Connection string=& Quot;data source=.; Initial catalog=ccxdemo; User Id=sa; password=123456; Multipleactiveresultsets=true; app=entityframework" "providername=" System.Data.EntityClient "/>
Joined the reflection grew a lot longer. Or to clearly see the database is a change, password and user name is changed, IP is where to change.
4. Take a look at the use of EF to find and change the implementation, become more concise
Ccxdemoentities db =Newccxdemoentities (); protected voidPage_Load (Objectsender, EventArgs e) { } //New protected voidButton1_Click (Objectsender, EventArgs e) {Gbook_message Gbookobj=NewGbook_message (); Gbookobj.username="CCX"; Gbookobj.body="Hello World"; Gbookobj.ip="127.0.0.1"; Gbookobj.createdate= DateTime.Parse ("2014-12-12"); DB.GBOOK_MESSAGE.ADD (Gbookobj); Db. SaveChanges (); Response.Write ("ok!!"); } //Modify protected voidButton2_Click (Objectsender, EventArgs e) { //find the Object varGbookobj = db.gBook_Message.Where (g = G.username = ="CCX"). FirstOrDefault (); //What's changedGbookobj.username ="Chunxiao"; //Perform modificationsdb. SaveChanges (); } //Delete protected voidButton3_Click (Objectsender, EventArgs e) {Gbook_message Gbookobj=NewGbook_message (); Gbookobj.id=1; //Add the object inDb.gBook_Message.Attach (gbookobj); //Mark as DeleteDb.gBook_Message.Remove (gbookobj); //Perform the deletedb. SaveChanges (); }
ASP. NET Mvc-ef Basics