In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
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 "ADO.NET how to customize objects", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "ADO.NET how to customize objects" bar!
The ADO.NET entity Framework provides tools to automatically generate object layers based on the conceptual schema definition language (CSDL) files of the entity data Model (EDM). These data classes can be customized to varying degrees, depending on the requirements of the application. You can also modify your own custom data class to use it for EDM. This is useful when you upgrade data classes from existing applications to use entity frameworks, or when you want more control over how data classes are created.
Extended partial data class
Types defined in EDM do not have the same associated methods as classes used in object-oriented programming. Instead, they contain only the attributes defined in EDM. You can add functionality to the object by extending the generated partial data class. When data classes are generated through the entity data model tool, they are implemented as partial classes. Partial classes split the definition of a class into two or more source files. Each source file contains a portion of the class definition, and when the application is compiled, all parts are combined.
Once you have partial classes, you can extend them with custom methods and properties in separate source files without worrying about losing your customizations when the generated file is refreshed.
Custom business logic
When using the generated data class, custom business logic can be invoked during some object service operations, such as changing properties or relationships. This business logic may include creating additional authentication or login when changing properties or calling SaveChanges. Custom business logic can be invoked by handling events raised by the object service or by defining custom partial methods that are called when the property is changed.
Custom data class
In some cases, extending a partial class simply by adding methods and properties may not provide enough flexibility. Suppose an existing .NET Framework application uses ADO.NET to load data from the database into a CLR object for use by that application. These objects may contain valuable customization and business logic that must be retained in the object layer. These customizations may prevent you from migrating your application to using entity frameworks. You may also want to have more control over entity types, rather than just extending the generated partial classes.
The recommended way to use custom data classes with EDM is to inherit from EntityObject. Entity Framework provides a set of interfaces that you can implement to use custom data classes with EDM if you cannot inherit from EntityObject or if you need more independence than the framework. When using custom data classes, you must apply properties to custom data classes and properties, and notify the object context when the properties are changed.
The generated data class inherits from EntityObject or ComplexObject. If you must use custom data classes with EDM, it is recommended that you modify your data classes to inherit from these two base classes. In this way, custom data classes will benefit from the change tracking and relationship management capabilities provided by EntityObject.
Keep the following points in mind when inheriting from EntityObject and ComplexObject:
◆ class and attribute names must match the entity types and attribute names defined in EDM's Conceptual Schema definition language (CSDL) file. If these names do not match, you must change the names of the data classes and properties, or update the names in CSDL and the associated mapping specification file MSL. For more information, see how to: customize an entity data Model to use ADO.NET Custom objects (entity Framework).
Every attribute of an entity type defined in ◆ CSDL must have an associated attribute in the custom data class. Custom data classes can have other properties that are not mapped to attributes defined in CSDL.
◆ you must apply attributes to custom data classes and properties. These properties provide explicit mapping between the object and the CSDL.
◆ to enable the object service to track changes made to ADO.NET custom objects, you must use the EntityObject change reporting method to report these changes in a specific mode.
The ◆ Entity Framework tool also generates other classes that simplify object programming. It is useful to use this code for custom data classes. For more information, see how to: use object Services for Custom objects (entity Framework).
When ◆ inherits from EntityObject, it must implement complex types by inheriting from ComplexObject.
Thank you for your reading, the above is the content of "ADO.NET how to customize the object", after the study of this article, I believe you have a deeper understanding of how to customize the object of ADO.NET, and the specific use 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.
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.