This example is the use LINQ2Dapper encapsulation efficiency than EntityFramwork, and supports and .NetCore .NetFramework frame, depends only on the Dapper
support above and .net framework4.6.1
.Net core2.0 support and more
1. use LINQ and SQL query
Connection to connect objects, details, see [LINQ2Dapper] Dapper To Linq most complete frame (a)
In order to give the user more choices, and can use LINQ query sql together to achieve some of the more complex logic
E.g
Connection.QuerySet<users>().Where<users>(x => x.roleId > 0 && x.roleId < 10).Where("users.code=@code", new { code = "3" }).ToList();
Where<users>(x => x.roleId > 0 && x.roleId < 10)为linq部分,Where("code=@code", new { code = "3" })为sql部分,
The final will be spliced into
SELECT * FROM users WHERE roleId>0 AND roleId<10 AND code=3
2. complex SQL also supports
Connection.QuerySet<users>().Where($@"roleId in(select roleId from role_Power where createDate<@createDate)", new
{
createDate = DateTime.Now
}).Where(x => x.code != "3").ToList();
This is a sub-query splicing
3. Note that even when the table
Connection.QuerySet<users>().Join<users, project_Role>(x => x.roleId, y => y.id).Where("project_Role.Id>@Id", new { Id = 1 }).ToList();
Even need to add the table prefix table, so as not to field the same name conflict
For example project_Role.Id, project_Role table name
Complete Demo can go to download on Github:
https://github.com/a935368322/Kogel.Dapper.Test
If you have questions you can also add QQ group discussion:
Technology Group 710 217 654
Open source framework, you can download the source code plus group