简体   繁体   中英

Simplified DB access in MVC controller with Webmatrix.Data api or?

My MVC application accesses DB2/400.

My DAL dll is being build around ADO.NET.

I need to build some simple controller actions. I dont want to go all over execute datareader methods just to get something simple and make my DAL fat.

These actions are mostly generic SQL Statements that fix some bugs in our enterprise systems, so i want to keep them simple and to alter them easy.

Is it ok if i use the webmatrix.data db api as i am using it in Web Pages ?

If not is there any simple alternative to that?

You can use WebMatrix.Data if you like, but you could also look at Massive ( https://github.com/robconery/massive ) which was inspired by WebMatrix.Data. It might be more in keeping with an enterprise-style approach.

I finally chose DAPER as my solution

It does exactly what i want. Extends IDBconnection and gives me what i need.

Example:

The equivalent in plain ado.net method would be 20-30 lines in order to execute the datareader and iterating through the results.

This is Dapper implementation:

private IDbConnection db = new OleDbConnection(ConfigurationManager.ConnectionStrings["ENTERBG"].ConnectionString);

ViewBag.F4211 = this.db.Query<dynamic>(@"SELECT sdivd,SDDOC,SDDCT,SDDOCO,SDDCTO,SDODOC,SDODCT FROM F4211 WHERE SDDCT IN
                                                    ('E8','E9','E0','EP','EC','EB','ED') AND SDODOC <> SDDOC AND
                                                    SDODOC<>0 order by sdivd");

The above example serves as an EXAMPLE. I am NOT gonna use the ViewBag for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM