dapper

[LINQ2Dapper]最完整Dapper To Linq框架---基础查询

匿名 (未验证) 提交于 2019-12-02 23:49:02
using Kogel.Dapper.Extension.Attributes; } (二)使用实例 首先添加命名空间 using Kogel.Dapper.Extension.MsSql; 可以通过数据库连接对象点出扩展方法,例如 var conn = new SqlConnection("数据库连接字符串"); 使用完记得释放连接对象,可以通过using或者 conn.Dispose(); 查询 var users = conn.QuerySet<users>().Where(x => x.code != "1").Get(); 模糊查询 var users1 = conn.QuerySet<users>().Where(x => x.name.Contains("Y")).Get(); 修改 users.name = Guid.NewGuid().ToString(); users.createDate = DateTime.Now; int result = conn.CommandSet<users>().Where(x => x.id == 4).Update(users); 修改查询 .Where(x => x.name.Contains("Y")) .UpdateSelect(x => new users { name = "Y11" })

What does the buffered parameter do in Dapper dot net?

一个人想着一个人 提交于 2019-12-02 23:20:52
Dapper dot net has a buffer parameter (a bool), but as far as I can tell the only thing it does is cast the result to a list before returning it. As per the documentation : Dapper's default behavior is to execute your sql and buffer the entire reader on return. This is ideal in most cases as it minimizes shared locks in the db and cuts down on db network time. However when executing huge queries you may need to minimize memory footprint and only load objects as needed. To do so pass, buffered: false into the Query method. I'm not sure how casting the result to a list accomplishes this. Am I

dapper -multi-mapping: flat sql return to nested objects

谁说我不能喝 提交于 2019-12-02 22:25:45
I have a company that contains an address object. The SQL return is flat, and I'm tring to get Query<> to load all the objects. cnn.Query<Company,Mailing,Physical,Company>("Sproc", (org,mail,phy) => { org.Mailing = mail; org.Physical = phy; return org; }, new { ListOfPartyId = stringList }, null, true, commandTimeout: null, commandType: CommandType.StoredProcedure, splitOn: "MailingId,PhyscialId").ToList(); I'm not sure if i have the SplitOn correct either. I'm getting the message: When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id Parameter name:

How to get Dapper to ignore/remove underscores in field names when mapping?

假装没事ソ 提交于 2019-12-02 22:12:12
There are many ways to map database field names to class names, but what is the simplest way to just remove the underscores? public IEnumerable<PersonResult> GetPerson(int personId) { using (var dbConnection = _dbConnectionFactory.Create(ConnectionStrings.ProjectXYZ)) { IEnumerable<PersonResult> result = dbConnection.Query<PersonResult>("fn_get_person", new { personId }, commandType: CommandType.StoredProcedure).ToList(); return result; } } Table and database fields: person -------- person_id full_name Class that works: (dapper already ignores capitalization) public class PersonResult { public

基于Dapper的开源Lambda扩展LnskyDB 2.0已支持多表查询

匿名 (未验证) 提交于 2019-12-02 22:06:11
LnskyDB LnskyDB是基于Dapper的Lambda扩展,支持按时间分库分表,也可以自定义分库分表方法.而且可以T4生成实体类免去手写实体类的烦恼. 文档地址: https://liningit.github.io/LnskyDB/ 开源地址: https://github.com/liningit/LnskyDB nuget地址: https://www.nuget.org/packages/LnskyDB/ 在此非常感谢SkyChenSky其中lambda表达式的解析参考了他的开源项目 Lambda表达式查询方便 基于Dapper的Lambda表达式扩展可以方便的进行查询筛选操作 支持分库分表 默认支持按年分库按月分表,也支持自定义分库分表.从此大数据不用愁 T4自动生成实体 有T4模板自动生成实体类,再也不用手写那些烦人的实体类了.仓储类及接口也支持自动生成 使用门槛低,快速上手 使用非常简单,可以快速上手 v2.0版本支持多表查询了 步骤如下 调用方法是通过 IQuery.OuterJoin 或者 IQuery.InnerJoin 进行连表查询,返回IJoinQuery对象. 可以调用 IJoinQuery.And,Or 进行条件过滤.调用 Select 返回 ISelectResult . 通过仓储的 GetList 或 GetPaging 进行返回结果.

Dapper扩展Dapper.Common框架 Linq To Sql 底层源码.net ORM框架

匿名 (未验证) 提交于 2019-12-02 22:06:11
源代码:https://github.com/1448376744/Dapper.CommonNUGET: Dapper.CommonQQ群:642555086 一、基本结构,此处可用委托,或动态代理完成 class Program { //类加载时配置一次 static Program() { //配置数据源为mysql SessionFactory.DataSource = ()=>new MySqlConnection("server=127.0.0.1;user id=root;password=1024;database=test;"); //下划线不敏感,默认不区分大小写 SessionFactory.MatchNamesWithUnderscores = true; //Session使用静态代理,记录会话日志,生产模式设置false SessionFactory.SessionProxy = true; } static void Main(string[] args) { //变量声明 ISession session = null; try { //开启一次数据会话 session = SessionFactory.GetSession(); //开启事物,取消自动提交 session.Open(false); //事物操作1 //事物操作2 //事物操作3 /

Dapper 链式查询 扩展

匿名 (未验证) 提交于 2019-12-02 22:06:11
Github地址 : https://github.com/mumumutou/DapperSqlMaker Demo: \ SelectDapperSqlMakerTest.cs InsertDapperSqlMakerTest.cs UpdateDapperSqlMakerTest.cs DeleteDapperSqlMakerTest.cs LockDapperUtilsqlite.cs 简单栗子: 1 [Test] 2 public void 三表联表分页测试() 3 { 4 LockPers lpmodel = new LockPers() { Name = "%蛋蛋%", IsDel = false}; 5 Users umodel = new Users() { UserName = "jiaojiao" }; 6 SynNote snmodel = new SynNote() { Name = "%木头%" }; 7 Expression<Func<LockPers, Users, SynNote, bool>> where = PredicateBuilder.WhereStart<LockPers, Users, SynNote>(); 8 where = where.And((lpw, uw, sn) => lpw.Name.Contains(lpmodel

基于Dapper二次封装了一个易用的ORM工具类:SqlDapperUtil

匿名 (未验证) 提交于 2019-12-02 22:06:11
基于Dapper二次封装了一个易用的ORM工具类:SqlDapperUtil,把日常能用到的各种CRUD都进行了简化封装,让普通程序员只需关注业务即可,因为非常简单,故直接贴源代码,大家若需使用可以直接复制到项目中,该SqlDapperUtil已广泛用于公司项目中。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Dapper; using System.Data; using System.Data.Common; using System.Reflection; using System.IO; using System.Collections.Concurrent; using System.Data.SqlClient; namespace Zuowj.Common { /// <summary> /// 基于Dapper的数据操作类封装的工具类 /// Author:左文俊 /// Date:2017/12/11 /// </summary> public class SqlDapperUtil { private static string

How to create an anonymous object with property names determined dynamically?

孤者浪人 提交于 2019-12-02 20:44:16
Given an array of values, I would like to create an anonymous object with properties based on these values. The property names would be simply "pN" where N is the index of the value in the array. For example, given object[] values = { 123, "foo" }; I would like to create the anonymous object new { p0 = 123, p1 = "foo" }; The only way I can think of to do this would be to to use a switch or if chain up to a reasonable number of parameters to support, but I was wondering if there was a more elegant way to do this: object[] parameterValues = new object[] { 123, "foo" }; dynamic values = null;

Store enum as string in database

霸气de小男生 提交于 2019-12-02 20:34:17
I am experimenting with dapper. I have a class which has an enum and the values are stored as strings in the database. This works with FluentNHibernate using GenericEnumMapper Is it possible to do the same with Dapper? Sam Saffron This is not built in at the moment, there is a proposed solution for this here: http://code.google.com/p/dapper-dot-net/issues/detail?id=24 which we are yet to decide on. I like the idea of extensible type converters As it stands the cleanest way to do this would be to define shadow property eg: class MyType { public MyEnum MyEnum {get; private set;} private string