Example of ADO. NET Entity Framework

Source: Internet
Author: User

This time is relatively blank. You can have time to play with the technology that is very popular. I know about Entity Framework. that's good. You can have time to play. It's really good if you have studied it recently. it reminds me of one sentence: Microsoft is making dummies, but time has made dummies.

The purpose of Microsoft's technology is simple, convenient, and easy to use. This is also one of the reasons why Microsoft has been unbeaten over the years. Compared with the complex configuration of Java, NetProgramI don't know how easy it is. Well, there seems to be some questions. Let's talk about EF.

First, let's take a look at how it was created. As shown in-1, the file type we created is this stuff. There are many similar examples in the creation step garden later.ArticleFor more information, see. I will not talk nonsense any more. I recommend several blog posts.

Figure-1

Http://www.cnblogs.com/fly_dragon/archive/2011/02/22/1961744.html

Http://www.cnblogs.com/scottckt/archive/2011/04/05/2006191.html

Http://www.cnblogs.com/webabcd/archive/2009/02/26/1398438.html

After the creation is complete, the file shown in-2 is generated. The DB here is the example northwind provided by sqlserver.

Figure 2

We can use NotePad to open the file northwindef. edmx and see what is in it? -3

Figure-3

It is also based on the XML file structure to move the objects in the DB Library to the front-endCodeIn short, it exists as a whole and is easier to operate. It is more evolved than the previous dbtable object class.

Next, let's take a look at how its cuid operation is performed? -4 and figure-5 are shown. the code is easy to understand, that is, first find the entity in the EF object, and then you can perform operations on the object. note that the last operation is the savechanges () method, which is simple. it has been encapsulated to this extent! Ah, the programmer is almost unemployed!

Figure 4

Figure 5

Here we will explain that there is another way to modify the operation. You can directly perform the operation without going through the query, as shown in-6. You can call the additional operation.

Figure 6

The most interesting part is the query operation. previously, I thought that I could use the SELECT statement to obtain the generic set of an object. After reading this, I found that this is not the case. take a look at the code, as shown in-7. since I have never touched the LINQ syntax before, it is still difficult to use it.

Figure-7

Another function is to generate a DB object in reverse order based on the EF project file. I will not introduce it here. A blog post has already been very detailed, and there are sample code downloads. I only want to say what others didn't say, haha.

Http://www.cnblogs.com/Lowlevel/archive/2011/02/23/ado_net_entity_framework_ctp5_quickstart.html#2031770

Finally, let's look at the business scenarios that EF technology can use. This is just based on my work experience. Whether it is applicable depends on the actual operation results.

Management software, especially software closely related to DB, such as ERP software, his, OA or personnel internal LAN management software, can be divided into sub-functional systems. for example, in ERP, these systems are generally proven and stable. its dB operations can use this technology. and it will indeed improve work efficiency.

In addition, every technology update has its own risks. It depends on the decision of decision makers. If the software design is reasonable and the scalability is good, replacement is very convenient.

 

Sample Code

Exampleef

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.