dapper

Call custom constructor with Dapper?

五迷三道 提交于 2019-11-29 11:19:31
问题 I'm trying to use Dapper to interface with the ASP.NET SQL Membership Provider tables. I wrapped the SqlMembershipProvider class and added an additional method to get me the MembershipUsers given a certain criteria relating to some custom tables I have. When querying the data with Dapper, it appears that Dapper first instantiates the class with a parameter-less constructor, and then "maps" the returned columns into the properties on the object. However, the UserName property on the

Dapper. Map to SQL Column with spaces in column names

安稳与你 提交于 2019-11-29 11:17:55
问题 I've managed to get something up and running today as small sandbox/POC project, but have seemed to bump my head on one issue... Question: Is there a way to get dapper to map to SQL column names with spaces in them. I have something to this effect as my result set. For example: SELECT 001 AS [Col 1], 901 AS [Col 2], 00454345345345435349 AS [Col 3], 03453453453454353458 AS [Col 4] FROM [Some Schema].[Some Table] And my class would look like this public class ClassA { public string Col1 { get;

How to return null from a Dapper query rather than default(T)?

 ̄綄美尐妖づ 提交于 2019-11-29 10:32:16
I'm using Dapper for some read-only database calls via a stored procedure. I've got a query that will either return 1 row or nothing. I'm using Dapper like this: using (var conn = new SqlConnection(ConnectionString)) { conn.Open(); return conn.Query<CaseOfficer>("API.GetCaseOfficer", new { Reference = reference }, commandType: CommandType.StoredProcedure).FirstOrDefault(); } The returned CaseOfficer object looks like this: public class CaseOfficer { public string Title { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; }

C#的dapper使用

你离开我真会死。 提交于 2019-11-29 10:07:00
Dapper是一款轻量级ORM工具( Github )。如果你在小的项目中,使用Entity Framework、NHibernate 来处理大数据访问及关系映射,未免有点杀鸡用牛刀。你又觉得ORM省时省力,这时Dapper 将是你不二的选择。 为什么选择Dapper 轻量。只有一个文件( SqlMapper.cs ),编译完成之后只有120k(好象是变胖了) 速度快。Dapper的速度接近与IDataReader,取列表的数据超过了DataTable。 支持多种数据库。Dapper可以在所有Ado.net Providers下工作,包括sqlite, sqlce, firebird, oracle, MySQL, PostgreSQL and SQL Server 可以映射一对一,一对多,多对多等多种关系。 性能高。通过Emit反射IDataReader的序列队列,来快速的得到和产生对象,性能不错。 支持FrameWork2.0,3.0,3.5,4.0,4.5 Dapper的安装 方法一:使用NuGet安装 打开visual studio的项目,依次点击 工具 , NuGet包管理器 , 管理解决方案的NuGet程序包 ; 再点击 浏览 , 搜索dapper , 点击搜索结果中的Dapper , 勾选项目 , 选择安装 ; 在 解决方案管理器中点击项目 , 查看引用 ,如果有

Dapper-小型ORM之王(C#.NET)

久未见 提交于 2019-11-29 10:00:33
ORM: 对象关系映射器,它直接将数据库映射到C#对象。 有很多ORM框架可用,Dapper是其中之一,被称为ORM之王。 下面是Dapper主要的一些功能: 速度快,性能好; 更少的代码行 对象映射 静态对象绑定 动态对象绑定 易于处理Sql语句 易于处理存储过程 直接操作IDBConnection类,该类直接向数据库提供平滑性和运行查询,而不是像在EF和ADO.NET中那样使用各种对象传递数据。 多个查询支持 支持存储过程 批量处理数据插入 允许基于多个输入获取多个数据 为什么选择Dapper Dapper是第二快的ORM 图片参照: Dapper dotnet . 直接使用IDBConnection对象执行CRUD操作; 通过数据库提供查询静态和动态数据; 获取简单或复杂数据类型的通用结果; Dapper允许同时存储批量数据。 如何安装Dapper 在Visual Studio中,创建一个新的控制台项目,并在解决方案资源管理器中右键单击引用,选择 “管理Nuget包...”包管理器,然后搜索Dapper,并使用NuGet包管理器控制台命令“install-package Dapper”,这将在项目中安装Dapper。 Dapper如何工作 主要包含三个步骤 第一步:使用连接字符串创建一个IDBConnection对象; 第二步:编写一个查询并将其存储在一个普通的字符串变量中;

Dapper Column number rather than column name?

不问归期 提交于 2019-11-29 07:47:13
I have a very similar question to Dapper-dot-net "no column name" , but the answer there is not getting me where I need. I'm writing a web interface and using dapper to get data from Stored Procedures from my client's ERP system. The SP returns 4 columns of data without column names. That being said the SP's are locked and I can't change them. I've tried to work around this by using a temp table in my query as Sam suggested. var grid = QueryMultiple(@"set nocount on declare @t table(Id int, Name nvarchar(max), AnotherId int) insert @t exec proc set nocount off select Id, Name from @t select Id

Dapper Multi-mapping Issue

本小妞迷上赌 提交于 2019-11-29 06:10:55
Keep running into "When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id" error for the below code-block: var accounts = DbConnection.Query<Account, Branch, Application, Account>( "select Accounts.*, SplitAccount = '', Branches.*, SplitBranch = '', Applications.*" + " from Accounts" + " join Branches" + " on Accounts.BranchId = Branches.BranchId" + " join Applications" + " on Accounts.ApplicationId = Applications.ApplicationId" + " where Accounts.AccountId <> 0", (account, branch, application) => { account.Branch = branch; account.Application =

“WHERE x IN y” clause with dapper and postgresql throwing 42601: syntax error at or near \\“$1\\”

孤街醉人 提交于 2019-11-29 05:46:53
I have an array of strings, and I'd like to have a query containing an IN clause, like: "... WHERE t.name IN ('foo', 'bar', 'baz')..>" Here's the final bit of my query, which contains a "where X in Y" clause: ... left join genre_tag_band_join tj on hb.id = tj.band_id or ob.id = tj.band_id left join genre_tags t on tj.genre_tag_id = t.id inner join venues v on e.venue_id = v.id where t.name IN @tagsParam... I make a Dapper call like this var shows = con.Query<Event, Band, Band, GenreTag, Venue, Event>(query, (e, hb, ob, gt, v) => { Event show; ... return e; }, new { tagsParam = tagsArr})

Dapper AddDynamicParams for IN statement with “dynamic” parameter name

£可爱£侵袭症+ 提交于 2019-11-29 05:18:23
问题 I have simple SQL string like this: "SELECT * FROM Office WHERE OfficeId IN @Ids" The thing is that the @Ids name is entered in an editor so it could be whatever, and my problem is that if I want to pass in, say an array of integers, it only works with Dapper if I use: var values = new DynamicParameters(); values.AddDynamicParams(new { Ids = new[] { 100, 101 } }); But this requires me to KNOW that the parameter name is Ids and that's not the case in my scenario. I can set a "dynamic parameter

快速web开发框架——力软 framework

旧巷老猫 提交于 2019-11-29 04:48:31
一个好的 web技术框架 往往与他速度有关,他需要帮助程序员尽可能快的完成项目的同时确保它的 安全性 , 敏捷框架 是基于 .net语言 的 web+ORM开发框架 ,其核心开发目标是 开发迅速,代码少,学习简单,功能强大,轻量级,易扩展 。在拥有.Net语言所以优势的同时,再拥有 java,php,Python 等动态语言的开发效率。这里补充说明一下, ORM ,即Object-Relational Mapping(对象关系映射),它的作用是在关系型数据库和业务实体对象之间作一个映射,这样,我们在具体的操作业务对象的时候,就不需要再去和复杂的SQL语句打交道,只需简单的操作对象的属性和方法。 敏捷开发框架具有以下特点: 1. 框架的主架构为基于 .net MVC 的 BS 架构 。 2. 后台 ORM 支持 EF 和 dapper 两种模式。 3. 用于实现各类业务系统,如 OA、ERP、MIS、CRM、电商平台 等系统的开发。框架本 身是一个可 二次开发 的开发平台,开发者可以根据开发向导进行配置直接生成功能模块;但是他又是一套 源代码 ,开发者也可以直接在 VS 中基于框架做发,甚至还可 以对开发框架进行开发扩展。 4. 强大的 权限管理组件 ,完成业务功能开发后,系统可以直接使用通用权限来管理业 务功能的操作权限及数据权限。 5. 集成 工作流引擎组件 ,使业务流程灵活可控