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"