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 fetch data from DB to ObjectContext

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to get the data from DB to ObjectContext". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get data from DB to ObjectContext".

Write an update class and pass in the objects to be updated, which may be client-side objects, such as JSON objects in ExtJs, or custom ActionScript objects in FLEX. These objects are passed in and transformed into server-side AEF entity objects.

Then you need to update the object, try a lot of ways, the data model of ADO code EF is still troublesome, you must have some understanding of state control such as EntityState, see the recommended address of the header.

To update a "detached object" to EF, and then to DB, you usually use the ApplyPropertyChanges () method, which can overwrite all objects. However, there is a very important problem with ADO code. Before implementing this method, there must be this actual column reference in ObjectContext. If not, it will report that "ObjectStateManager does not contain ObjectStateEntry with references to objects of type". So there are two ways.

The data is fetched from the DB to the ObjectContext through the primary key. In this way, it is the simplest, but it feels like you have to perform a "get" before the update, and the ADO code is very upset in terms of performance. However, after all, it is Key acquisition, I believe that the order of magnitude of millions will not be a big problem. This method is also recommended by me: as follows

The specific ADO code is as follows:

Public string UpdateDepartment (Department dept) {using (var db = new FlexDbEntities ()) {/ / this sentence must have ah! Department o1 = db.Department.First (p = > p.Id = = dept.Id); db.ApplyPropertyChanges ("Department", dept); db.SaveChanges () }} Thank you for your reading. The above is the content of "how to get data from DB to ObjectContext". After the study of this article, I believe you have a deeper understanding of how to get data from DB to ObjectContext, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report