How to build an EF environment? (Entity Framework), efentity

Source: Internet
Author: User

How to build an EF environment? (Entity Framework), efentity

1. What is EF?

EF is an Entity layer Framework encapsulated by. net for database interaction. Its full name is Entity Framework.

 

2. EF construction:

After the creation, we can see the content in it:

Let's take a look at what it has in it separately?

2. 1. After ef is created, we [open method-XML text editor] in EF to see what SSDL, CSDL, and MAPPING are the most important ones?

 

2.2.T4 Template

We call this thing the T4 template. Its function is to read the content in EF [. edmx] and generate class files one by one.

 

2.3.EF another important thing is the EF context object. [We call the add, delete, modify, and query method of the EF context object by instantiating it]

3. Use EF for a small logon example:

Create a web page: [some code]

1 <div> 2 <table> 3 <tr> 4 <td> User name: </td> 5 <td> 6 <asp: textBox ID = "txtLoginUserName" runat = "server"> </asp: TextBox> 7 </td> 8 </tr> 9 <tr> 10 <td> password: </td> 11 <td> 12 <asp: TextBox ID = "txtLoginPwd" runat = "server" TextMode = "Password"> </asp: textBox> 13 </td> 14 </tr> 15 <tr> 16 <td> 17 <asp: button ID = "BtnLogin" runat = "server" Text = "login" OnClick = "BtnLogin_Click"/> 18 </td> 19 <td> <a href = "javascript ;: "> forgot password </a> </td> 20 </tr> 21 </table> 22 </div>
1 protected void Page_Load (object sender, EventArgs e) 2 {3 4} 5 // instantiate an EF context object 6 sq_rEntities db = new sq_rEntities (); 7 protected void BtnLogin_Click (object sender, EventArgs e) 8 {9 string username = txtLoginUserName. text. trim (); 10 string pwd = txtLoginPwd. text. trim (); 11 // operate the UserInfor table through the entity object of EF, execute the lamada condition, 12 // db. set <UserInfor> (). where (u => u. userName = username & u. pwd = pwd) may be empty, Fi RstOrDefault gets the first 13 UserInfor user = db. set <UserInfor> (). where (u => u. userName = username & u. pwd = pwd ). firstOrDefault (); 14 // determines whether it is null. 15 if (user = null) 16 {17 Response. write ("incorrect user name or password! "); 18} 19 else20 {21 Response. Write (" Logon successful! "); 22} 23}

 

SQL statement Process Monitoring: EF without SQL injection:

Run-log on to the logon page

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.