dapper

Dapper throws “Invalid type owner for DynamicMethod.”

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I'm trying to use Dapper.net and I'm liking it. What I'm not liking is when I try to batch-insert entities and I get the following error thrown: Invalid type owner for DynamicMethod. at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility, Boolean transparentMethod, StackCrawlMark& stackMark) at System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes,

Can I specify DB column names for dapper-dot-net mappings?

泪湿孤枕 提交于 2019-12-03 01:23:26
Is there a way with dapper-dot-net to use an attribute to specify column names that should be used and not the property name? public class Code { public int Id { get; set; } public string Type { get; set; } // This is called code in the table. public string Value { get; set; } public string Description { get; set; } } I'd like to be able to name my properties whatever I choose. Our database has no consistent naming convention. If not with dapper, are there any additional similar options? You can also check out Dapper-Extensions . Dapper Extensions is a small library that complements Dapper by

Dapper multi insert returning inserted objects

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Using Dapper I would like to implement a method that takes an IEnumberable of objects of type User . Now, User looks as follows: public class User { public int UserId { get; internal set; } public DateTime DateCreated { get; internal set; } public DateTime DateChanged { get; internal set; } public string Username { get; set; } } The point here is that UserId , DateCreated and DateChanged shall never be set via object, hence the internal keyword. Instead the database will populate these values. Because the objects are therefore modified as

How to pass a null parameter with Dapper

我的梦境 提交于 2019-12-03 01:04:48
I have a stored procedure that has a parameter with no default value, but it can be null. But I can't figure out how to pass null with Dapper. I can do it just fine in ADO. connection.Execute("spLMS_UpdateLMSLCarrier", new { **RouteId = DBNull.Value**, CarrierId = carrierID, UserId = userID, TotalRouteRateCarrierId = totalRouteRateCarrierId }, commandType: CommandType.StoredProcedure); Exception: System.NotSupportedException was caught Message=The member RouteId of type System.DBNull cannot be used as a parameter value Source=Dapper StackTrace: at Dapper.SqlMapper.LookupDbType(Type type,

How to use generic and Nullable<T> types in Dapper for materialization?

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this call: public IObservable<T> Subscribe(object topic, string service, string connectionString, string query) { try { this.connection.ConnectionString = connectionString; this.connection.Open(); this.connection.Query<T>(query, new { transactionid = topic }).ToObservable().Subscribe(message => this.subject.OnNext(message)); return this.subject; } catch (Exception e) { this.subject.OnError(e); return this.subject; } finally { this.subject.OnCompleted(); this.connection.Close(); } } This is my query: with IDS as (select L1_ID, L2_ID,

Java Micro ORM equivalent [closed]

余生颓废 提交于 2019-12-03 00:52:53
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . What would be the closest equivalent in Java to a Micro ORM such as Dapper, PetaPoco, Massive or CodingHorror? 回答1: I recommend Spring JDBC templates. While it's not a "true" ORM, it's a pleasure to use where Hibernate seems to be an overkill. 回答2: sql2o seems like a Dapper alternative - thin wrapper around JDBC

asp.net core使用Dapper操作Sqlserver/Oracle

匿名 (未验证) 提交于 2019-12-03 00:41:02
无废话,还是先上git地址:https://gitee.com/jimmyTown_admin_admin/DapperInCoreDemo.git 结构如下: 引用OK后,根据Dapper的封装定义对应的通用接口 主要是针对dapper本身的实现作一些CURD的封装 引入Swashbuckle.AspNetCore及log4net 当然日志也可以不使用Log4net而使用Microsoft.Extensions.Logging下的ILoggerFactory 运行看看效果(我这里将lauchSetting.json中的开始url变更为"launchUrl": "api/student" 默认显示所有学生信息,我们可以到swagger页面 这里就不一一尝试了,大家可以下载代码尝试 原文:https://www.cnblogs.com/AreaWhere/p/9313403.html

Dapper学习(三)之其他用法

匿名 (未验证) 提交于 2019-12-03 00:05:01
这里说的其他用法,是指 Async,Buffered,Transaction,Stored Procedure。 1. 首先 dapper支持异步 ExecuteAsync, QueryAsync, QueryFirstAsync, QueryFirstOrDefaultAsync, QuerySingleAsync, QuerySingleOrDefaultAsync, QueryMultipleAsync ExecuteAsync 用法示例: string sql = "INSERT INTO Customers (CustomerName) Values (@CustomerName);" ; using ( var connection = new SqlConnection ( FiddleHelper . GetConnectionStringSqlServerW3Schools ())) { var affectedRows = connection . ExecuteAsync ( sql , new { CustomerName = "Mark" }). Result ; Console . WriteLine ( affectedRows ); var customer = connection . Query < Customer >( "Select *

Dapperѧϰ(1)

匿名 (未验证) 提交于 2019-12-03 00:03:02
Dapper是一个用于.NET的简单的对象映射,并且在速度上有着轻ORM之王的称号。 Dapper扩展IDbConnection,提供有用的扩展方法来查询数据库。 那么Dapper是怎样工作的呢? 总共三步: 创建一个IDbConnection对象 写一个语句来执行CRUD操作 传递语句作为Execute方法的一个参数 因为这篇文章主要是为了学习其中一些方法的使用,所以,这里不再叙述安装等的一些使用,有需要的同学可以参考: https://dapper-tutorial.net/dapper 1.Execute Execute是可以被IDbConnection类型的任何对象调用的扩展方法。它可以执行一个命令一次或者很多次,并且返回受影响的行数。 这个方法可以用于执行: 存储过程(Stored Procedure) 插入语句(INSERT statement) 更新语句(UPDATE statement) 删除语句(DELETE statement) 下面的表格,展示了Execute方法的参数 这里给出一个实现代码的示例,其余部分直接在官网上的示例上面记录学习。 using Dapper; using System; using System.Data.SqlClient; using System.Runtime.Serialization; namespace Dapper

关于dapper的事务处理

匿名 (未验证) 提交于 2019-12-02 23:49:02
dapper:一个轻量级的ORM框架 为了方便调用,自己编写了一个DapperHelper.cs 代码如下: using Dapper; using Model.DB; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; namespace Tools.DB { public class DapperHelper { private static DapperHelper dapperHelper; private static readonly object lockObj = new object(); public static string connStr = string.Empty; private DapperHelper() { //数据库连接字符串 connStr = Conn.CreateInstance().ConnStr; } public static DapperHelper CreateDapperHelper() { if (dapperHelper == null) { lock (lockObj) { if (dapperHelper == null) {