In my previous blog, I briefly explained an "ORM" approach to memory-oriented data sets, and also mentioned that my design implementation might not be called "ORM", let's call it s-orm.
Maybe some of the small partners did not understand my ideas and objectives, and the traditional ORM framework made a simple comparison, in fact, I do not create a database table structure of the entity object model, but I want to use the traditional ADO. NET mode to manipulate the database , and the ADO. NET result data set, the loose dynamic mapping, and provides some class ORM automation methods, simplifying the traditional ADO operation of the database.
Again this is a brief description of the design objectives:
1. Support all database native operations (ADO/Microsoft Enterprise Library based data module)
2. releasing a corresponding relationship to the database table model, the developer has the flexibility to specify the mapping relationship .
3. Support direct use of SQL statements and dynamic mapping based on query results.
4. Supports calling stored procedures and dynamically mapping based on query results.
5. Support Automated transaction processing, can be automatically rolled back.
6. Supports a one-to-many mapping relationship where an entity class can be mapped to multiple tables.
7. Support Auto Fill/complement data in entity class.
8. High performance, flexibility and high maintainability.
For more information, refer to my previous blog: http://www.cnblogs.com/sheng_chao/p/4553832.html
Here are a few examples of how to add a few scenarios:
1. There are several fields (>2) in the table User, and now only want to take out 2 of the fields to establish an object instance and serialize it to the client.
Define an object that contains the required 2 fields (assuming user_a), specify the corresponding relationship of the object to the database table structure through the Attribute provided by S-orm, and use the Fill method to automatically populate the object's properties.
[Table ("User")] Public classuser_a {[Key] PublicGuid Id {Get; Set; } Public stringName {Get; Set; } Public intAge {Get; Set; } }
Populate the object:
Public user_a getuser_a (Guid ID) { new user_a (); = ID; if (_database.fill<user_a>(User)) return user; Else return NULL ; }
2. You want to use SQL statements to query data from a database table and instantiate the result as a strongly typed object instance.
In this scenario, the result set may come from more than one table, or the result set is simply a complex statistic of some data. Completely unrelated to the design of the table structure, using S-orm is very simple, first defining the object type as above, and then using a similar approach:
PublicList<user_a>GetData (Guid id) {List<CommandParameter> parameterlist =NewList<commandparameter>(); Parameterlist.add (NewCommandParameter ("@userId", id)); List<User_A> userlist = _database.select<user_a>( "SELECT * FROM [user] INNER joins [Product] on [user]. [Id] = [Product]. [UserId] WHERE [User]. [Id]= @userId", parameterlist); returnuserlist; }
As you can see here, S-orm is very simple to do, and for the data set returned by ADO, user_a with the specified object type, dynamically mapping to get an instance collection of user_a types.
Note: S-orm does not enforce that the object type definition corresponds to the memory dataset field one by one, which is described in more detail in the previous blog, please refer to.
3. Call the stored procedure to get the result of the strongly typed object collection.
The above example is basically consistent, for complex queries, directly using the powerful query capabilities provided by the database: views, stored procedures, custom functions, the resulting set of results are automatically mapped to a strongly typed object instance.
Define the type of object we want, don't repeat it, and then use S-orm:
PublicList<record>GetReport (Guid id) {List<CommandParameter> parameterlist =NewList<commandparameter>(); Parameterlist.add (NewCommandParameter ("@id", id)); DataSet DataSet=_database.executedataset (CommandType.StoredProcedure,"Getrecord", Parameterlist,"Result"); List<Record> reportlist = relationalmappingunity.select<record>(DataSet); returnreportlist; }
The above 3 examples basically represent the design purpose of S-orm, while S-orm also provides a number of related ancillary functions, and similar to the traditional ORM addition and deletion method, please refer to the previous blog detailed introduction.
Source code Download : Http://121.40.198.87:8010/S-ORM.zip
Small ads
Bloggers are paying attention to the relevant senior positions in Nanjing
Jiangsu Telecom Technical Manager No. 10,000th, currently a foreign-funded company team Leader
Biography:http://121.40.198.87:8010/
Use. NET WinForm to develop a WYSIWYG IDE development environment that allows you to build your application without writing code directly:
Http://www.cnblogs.com/sheng_chao/p/4387249.html
Development of online customer service system using wpf+ ASP (one):
Http://www.cnblogs.com/sheng_chao/p/4548146.html
(source download) high flexibility, high applicability, high performance, lightweight ORM implementation