Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build EF environment

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to build an EF environment, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

What is 1.EF?

EF is an entity layer framework encapsulated by. Net for database interaction, and its full name is Entity Framework.

2.EF build:

After the new project is created, we can see the contents:

Can we take a look at what's in it separately?

2.1. After creating ef, we can see that SSDL,CSDL,MAPPING is the most important thing in EF [Open Mode-XML text Editor]. What do they do?

2.2.T4 template

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

2.3.EF also has an important thing called the EF context object. [we call its add, delete, modify and query method by instantiating the EF context object]

3. Use EF as a small example of login:

Create a new web page: [partial code]

12 3 4 user name: 5 6 7 8 9 10 password: 11 12 13 14 15 16 17 18 19 forgot password 20 21 22 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 / / through the entity object of EF, manipulate the UserInfor table and execute the lamada condition, 12 / / db.Set (). Where (u = > u.UserName = = username & & u.Pwd = = pwd) may be empty, and FirstOrDefault gets * * 13 UserInfor user = db.Set (). Where (u = > u.UserName = = username & & u.Pwd = = pwd). FirstOrDefault () 14 / / determine whether it is empty 15 if (user = = null) 16 {17 Response.Write ("wrong username or password!") ; 18} 19 else 20 {21 Response.Write ("login succeeded!"); 22} 23}

Sql statement process monitoring: EF has no SQL injection:

Run-Login on the login page.

Thank you for reading this article carefully. I hope the article "how to build an EF Environment" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report