dapper

Is there any way to trace\log the sql using Dapper?

青春壹個敷衍的年華 提交于 2019-12-17 16:01:40
问题 Is there a way to dump the generated sql to the Debug log or something? I'm using it in a winforms solution so the mini-profiler idea won't work for me. 回答1: I got the same issue and implemented some code after doing some search but having no ready-to-use stuff. There is a package on nuget MiniProfiler.Integrations I would like to share. Update V2 : it supports to work with other database servers, for MySQL it requires to have MiniProfiler.Integrations.MySql Below are steps to work with SQL

How to create arguments for a Dapper query dynamically

梦想的初衷 提交于 2019-12-17 15:15:13
问题 I have a dictionary of values Eg "Name": "Alex" Is there a way to pass this to Dapper as arguments for a query? Here is an example showing what I want to do. IDictionary<string, string> args = GetArgsFromSomewhere(); string query = "select * from people where Name = @Name"; var stuff = connection.Query<ExtractionRecord>(query, args); 回答1: Yes: var dbArgs = new DynamicParameters(); foreach(var pair in args) dbArgs.Add(pair.Key, pair.Value); Then pass dbArgs in place of args : var stuff =

Using Dapper with Oracle stored procedures which return cursors

五迷三道 提交于 2019-12-17 10:39:05
问题 How would one go about using Dapper with Oracle stored procedures which return cursors? var p = new DynamicParameters(); p.Add("foo", "bar"); p.Add("baz_cursor", dbType: DbType.? , direction: ParameterDirection.Output); Here, the DbType is System.Data.DbType which does not have a Cursor member. I've tried using DbType.Object but that does not work with both OracleClient and OracleDataAcess. What would be a possible way to use OracleType or OracleDbType instead? 回答1: You would have to

Dapper.Rainbow VS Dapper.Contrib

可紊 提交于 2019-12-17 08:11:26
问题 Can someone please explain the difference between Dapper.Rainbow vs. Dapper.Contrib ? I mean when do you use SqlMapperExtensions.cs of Dapper.Contrib and when should you use Dapper.Rainbow? 回答1: I’ve been using Dapper for a while now and have wondered what the Contrib and Rainbow projects were all about myself. After a bit of code review, here are my thoughts on their uses: Dapper.Contrib Contrib provides a set of extension methods on the IDbConnection interface for basic CRUD operations: Get

Dapper.Rainbow VS Dapper.Contrib

自作多情 提交于 2019-12-17 08:11:23
问题 Can someone please explain the difference between Dapper.Rainbow vs. Dapper.Contrib ? I mean when do you use SqlMapperExtensions.cs of Dapper.Contrib and when should you use Dapper.Rainbow? 回答1: I’ve been using Dapper for a while now and have wondered what the Contrib and Rainbow projects were all about myself. After a bit of code review, here are my thoughts on their uses: Dapper.Contrib Contrib provides a set of extension methods on the IDbConnection interface for basic CRUD operations: Get

Multi-Mapper to create object hierarchy

蹲街弑〆低调 提交于 2019-12-17 02:39:16
问题 I've been playing around with this for a bit, because it seems like it feels a lot like the documented posts/users example, but its slightly different and isn't working for me. Assuming the following simplified setup (a contact has multiple phone numbers): public class Contact { public int ContactID { get; set; } public string ContactName { get; set; } public IEnumerable<Phone> Phones { get; set; } } public class Phone { public int PhoneId { get; set; } public int ContactID { get; set; } //

How does Dapper execute query without explicitly opening connection?

喜你入骨 提交于 2019-12-13 18:27:06
问题 We are using Dapper for some data access activity and are using the standard recommended approach for connecting to database as follows: public static Func<DbConnection> ConnectionFactory = () => new SqlConnection(ConnectionString); However, if we try and execute a statement, in the docs it show that you need to first state: using (var conn = ConnectionFactory()) { conn.Open(); var result = await conn.ExecuteAsync(sql, p, commandType: CommandType.StoredProcedure); return result; } That means,

Dapper-dot-net “no column name”

与世无争的帅哥 提交于 2019-12-13 15:12:14
问题 I have a result set that might look like this: ID (no column name) anotherID ---- ---------------- ---------- 1 super 3 1 super 4 3 duper 6 4 really 7 4 really 8 I have 2 issues: First: How do I use dapper with a column with no name? Second: I want to have a parent child relationship such that I get 3 objects each with a list of anotherID's for example: public class MyObject { public int ID public string Name public int[] Children } 回答1: Well, un-named columns are not supported by dapper. I

How to bulk insert in SQL using Dapper in C# [duplicate]

允我心安 提交于 2019-12-13 11:02:59
问题 This question already has answers here : Does Dapper support inserting multiple rows in a single query? (2 answers) Closed 6 months ago . I am using C# Dapper with MYSQL. I have a list of classes that i want to insert into MySQL table. I used to do it using TVP in MS SQL, how do we do it in MySQL. 回答1: Disclaimer : I'm the owner of Dapper Plus This project is not free but supports MySQL and offers all bulk operations: BulkInsert BulkUpdate BulkDelete BulkMerge And some more options such as

【微服务架构】调用链追踪系统对比

拥有回忆 提交于 2019-12-13 10:47:35
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 概述 当代的互联网服务,通常都是用复杂的、大规模分布式集群来实现的。互联网应用构建在不同的服务集上,这些服务有可能是由不同的团队开发、可能使用不同的编程语言来实现、有可能布在了几千台服务器,横跨多个不同的数据中心。因此,需要一个用于分析性能问题的系统可以监控那些横跨了不同的应用、不同的服务器之间的关联动作,调用链追踪系统应运而生。 目标 分布式调用链追踪系统一般有以下五个目标: 低消耗(low-overhead)调用链追踪埋点不能占用链路上太长的时间,也不应消耗太多的机器资源。 低侵入(low-invasiveness)作为非业务组件,应当尽可能少侵入或者不侵入其他业务系统,保持对使用方的透明性,减少开发人员的负担和接入门槛。 可扩展(scalability)整个调用链追踪通路都应该可扩展,以应对不断接入的服务和公司未来的发展。 时效性(time-efficient)从追踪数据采集,分析处理,查询,展示的整个通路都要尽量快速。 决策支持(decision-support)需要为业务定位问题,分析服务,提供丰富清晰的报表。 功能 调用链追踪系统通常包含的功能如下: 对调用请求的整个链路进行追踪,分析每个环节的耗时,协助开发运维人员找到性能瓶颈 找出服务之间的依赖拓扑关系,如每个服务依赖哪些服务