Dappers: Dao-Part II based on Dapper.net Extension

Source: Internet
Author: User

Those who are used to Linq2Sql certainly love the inline style from... where... select and strong writing.
Unfortunately, I am not. For table Association, this writing method and its final SQL analysis are very egg pain. As a result, the Dapper author's blog has the experience of converting Linq2sql into SQL dapper.

 

However, I fully agree that Lambda is easier to write, more elegant, and more powerful in general simple queries. (For Lambda parsing to convert SQL statements, please refer to here)

So I added an interface to my Dappers. All these interfaces are SQL-oriented and cross-oracle/SQL server-oriented.

 

1. If SQL statements are not completely written, the basic information of the database is still required.

[System. Data. Linq. Mapping. Table (Name = "SYS_OFFICE")]
Public class MyOffice
{
[System. Data. Linq. Mapping. Column (Name = "OfficeId", IsPrimaryKey = true)]
Public string Id {get; set ;}
Public string Name {get; set ;}
Public string OfficeType {get; set ;}
......
 

2. Query <T> (whereExpression)


Var user = dao. Query <MyUser> (u => u. UserCode. StartsWith ("chen"); // you can use mapping. Otherwise, you do not need to describe mapping.

Var user1 = dao. Query <MyUser, MyOffice> ("select t. * from SYS_USER t inner join SYS_Office t1 on t. OfficeId = t1.Id ",
(U, o) => u. UserCode. StartsWith ("chen") & o. Name. Contains ("Office "));

Var user2 = dao. Query <IDictionary, MyUser, MyOffice> ("select t1.UserCode, t1.Name from SYS_USER t1 inner join SYS_Office t2 on t1.OfficeId = t2.Id ",
(D, u, o) => u. UserCode. StartsWith ("chen") & o. Name. Length> 4 );
 

 

3. UnitTest result

 

Author: "Yang's essay-the art of reuse and reconstruction"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.