In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "Entity Framework 7 shadow attributes how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Entity Framework 7 shadow attributes how to use" this article.
Shadow properties are fields that do not exist in the class itself, but Entity Framework thinks they exist. They can participate in queries, create / update operations, and database migrations. Microsoft believes that there are two main application scenarios for shadow properties:
Allow the data access layer to access properties that should not be exposed by the domain model to other parts of the application
Allows developers to efficiently add attributes to classes without source code
The shadow property is defined in the OnModelCreating event, which is an overloaded method in DBContext. Here is an example of binding the DataTime attribute LastUpdated to a Blog entity.
Protected override void OnModelCreating (ModelBuilder modelBuilder) {modelBuilder.Entity () .Property ("LastUpdated");
A common use case for this property is to automatically assign a value to the LastUpdated property when the save operation is performed. To do this, you can use DBContext.ChangeTracker to get a list of objects of type DBEntry. You can write like this:
Foreach (var item in modifiedEntries) {Item.Property ("LastModified") .CurrentValue = DateTime.Now;}
This can generally be achieved by overloading the SaveChanges () method of the DBContext class. With the overload here, you can update all the data that needs to be updated without having to repeat the code in every place where the data is updated.
When ChangeTracker is suitable for modifying and saving events, you will want to bypass DBEntry and access shadow properties directly. You can do this through the EF.Property function, as follows:
EF.Property (entity, "LastModified")
This expression is placed in a query to generate server-side WHERE and ORDER BY clauses.
The above is all the content of the article "how to use Shadow attributes in Entity Framework 7". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.