dapper

Dapper.NET and IQueryable

别等时光非礼了梦想. 提交于 2019-12-03 04:44:42
Is there a plan to make Dapper.net compatible with IQueryable interfaces? If not, what's the workaround to use Dapper with "Expression Trees" filters? No, there are no plans to do this. It is far far outside what dapper tries to do. So far that I would say it is antithetical. Dapper core tries to be the friend to those who love their SQL. You can get IQueryable from IEnumerable using the built-in extension method AsQueryable in System.Linq namespace public IQueryable<Order> GetOrdersAsQuerable() { IEnumerable<Order> qry= GetOrders(); //using Query<T> //use the built-in extension method

Adjusting CommandTimeout in Dapper.NET?

对着背影说爱祢 提交于 2019-12-03 04:40:36
问题 I'm trying to run SQL backups through a stored procedure through Dapper (the rest of my app uses Dapper so I'd prefer to keep this portion running through it as well). It works just fine until the CommandTimeout kicks in. using (var c = SqlConnection(connstring)) { c.Open(); var p = new DynamicParameters(); // fill out p c.Execute("xp_backup_database", p, commandType: CommandType.StoredProcedure); } The only CommandTimeout setting I know of is in SqlCommand. Is there a way to set this via

How do I use 'Where In' in Dapper

我只是一个虾纸丫 提交于 2019-12-03 04:36:24
I've been trying unsuccessfully now for a while to use an IEnumerable<string> with a WHERE IN clause in Dapper. In the documentation, it does say that IEnumerable<int> is supported for use in a WHERE IN but I can't even get that to work. Dapper allow you to pass in IEnumerable<int> and will automatically parameterize your query. The error message I keep receiving is an Sql syntax error. Incorrect syntax near ','. I've put together some test code that I hope will demonstrate what I am trying to achieve. string connString = "Server=*.*.*.*;Database=*;User Id=*;Password=*;"; string sqlStringIn =

Dapper安装与使用

故事扮演 提交于 2019-12-03 04:18:29
1、VS2015直接使用nuget包搜索Dapper,安装时报错:显示版本不兼容。 于是使用命令安装dapper低版本。 步骤: 打开项目,vs工具---Nuget包管理器--程序包管理器控制台 然后在控制台里面输入命令: Install-package dapper -Version 1.50.2 安装成功。 来源: https://www.cnblogs.com/zl181015/p/11776663.html

Using Async Await keywords with Dapper

走远了吗. 提交于 2019-12-03 04:14:14
问题 I want to use a micro-orm and decided to go with Dapper. But can't seem to find any mentions of it supporting the new async/await syntax. Async queries are important for me. Can someone provide a code example of an async query being made with Dapper using the await keyword ? 回答1: Dapper when targeting .NET 4.5 has full support for TPL usage, via the methods ending in *Async - QueryAsync etc. Specifically, the .NET 4.5 build includes this extra set of methods 回答2: Here's a sample Yaron public

Can't get multi-mapping to work in Dapper

吃可爱长大的小学妹 提交于 2019-12-03 03:51:26
问题 Playing around with Dapper, I'm quite pleased with the results so far - intriguing! But now, my next scenario would be to read data from two tables - a Student and an Address table. Student table has a primary key of StudentID (INT IDENTITY) , Address has an AddressID (INT IDENTITY) . Student also has an FK called AddressID linking into the Address table. My idea was to create two classes, one for each table, with the properties I'm interested in. Additionally, I put an PrimaryAddress

Custom mapping in Dapper

白昼怎懂夜的黑 提交于 2019-12-03 03:36:09
I'm attempting to use a CTE with Dapper and multi-mapping to get paged results. I'm hitting an inconvenience with duplicate columns; the CTE is preventing me from having to Name columns for example. I would like to map the following query onto the following objects, not the mismatch between the column names and properties. Query: WITH TempSites AS( SELECT [S].[SiteID], [S].[Name] AS [SiteName], [S].[Description], [L].[LocationID], [L].[Name] AS [LocationName], [L].[Description] AS [LocationDescription], [L].[SiteID] AS [LocationSiteID], [L].[ReportingID] FROM ( SELECT * FROM [dbo].[Sites] [1_S

How to pass a null parameter with Dapper

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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

Call stored procedure from dapper which accept list of user defined table type

懵懂的女人 提交于 2019-12-03 01:56:57
I have a stored procedure InsertCars which accepts list of user defined table type CarType . CREATE TYPE dbo.CarType AS TABLE ( CARID int null, CARNAME varchar(800) not null, ); CREATE PROCEDURE dbo.InsertCars @Cars AS CarType READONLY AS -- RETURN COUNT OF INSERTED ROWS END I need call this stored procedure from Dapper. I googled it and found some solutions. var param = new DynamicParameters(new{CARID= 66, CARNAME= "Volvo"}); var result = con.Query("InsertCars", param, commandType: CommandType.StoredProcedure); But I get an error: Procedure or function InsertCars has too many arguments

SELECT * FROM X WHERE id IN (…) with Dapper ORM

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the best way to write a query with IN clause using Dapper ORM when the list of values for the IN clause is coming from business logic? For example let's say I have a query: SELECT * FROM SomeTable WHERE id IN (commaSeparatedListOfIDs) The commaSeparatedListOfIDs is being passed in from business logic and it can be any type of IEnumerable(of Integer) . How would I construct a query in this case? Do I have to do what I've been doing so far which is basically string concatenation or is there some sort of advanced parameter mapping