dapper

is there an ExecuteScalar in Dapper

我的未来我决定 提交于 2019-12-21 06:49:05
问题 it looks like there was an ExecuteScalar in Dapper... http://code.google.com/p/dapper-dot-net/issues/attachmentText?id=22&aid=220000000&name=ExecuteScalar.cs&token=9e2fd8899022f507b140ffb883c60e34 Was ExecuteScalar renamed or removed? Can this now be achieved with .Query or .Query<T>? 回答1: ExecuteScalar was just added in 1.28: https://www.nuget.org/packages/Dapper 回答2: I was able to call ExecuteScalar< T > with version 1.42.0 public Boolean BeforeToday(DateTime dateInQuestion) { try { using

Dapper Multi-map next level

橙三吉。 提交于 2019-12-21 04:08:19
问题 I'm using multiple mapping for a current query and now I need to map another object on the initial query. For example: public class Part { public int Id { get; set; } public string Name { get; set; } public Address Address { get; set; } } public class Address { public int Id { get; set; } public string Street { get; set; } public SiteOu Ou { get; set; } } public class SiteOu public int Id { get; set; } public string Name { get; set; } } Dapper: connection.Query<Part, Address, Part>(sql, (part

Dapper: How to get value from DapperRow if column name is “count(*)”?

泄露秘密 提交于 2019-12-21 03:53:22
问题 I have a dynamic result from Dapper query that contains records like this: {DapperRow, billing_currency_code = 'USD', count(*) = '6'} I'm able to access 'USD' by using rowVariable.billing_currency_code To get '6' value I tried rowVariable["count(*)"] and rowVariable.kv["count(*)"] and unfortunately nothing works... I can't change the count(*) column name in my case How to get the '6' value from the rowVariable of type DapperRow in such case? 回答1: If the column name genuinely is "count(*)" ,

Fastest way to map result of SqlDataReader to object

故事扮演 提交于 2019-12-21 02:28:16
问题 I'm comparing materialize time between Dapper and ADO.NET and Dapper. Ultimately, Dapper tend to faster than ADO.NET, though the first time a given fetch query was executed is slower than ADO.NET. a few result show that Dapper a little bit faster than ADO.NET(almost all of result show that it comparable though) So I think I'm using inefficient approach to map result of SqlDataReader to object. This is my code var sql = "SELECT * FROM Sales.SalesOrderHeader WHERE SalesOrderID = @Id"; var conn

Dapper Bulk Insert Returning Serial IDs

泄露秘密 提交于 2019-12-20 19:47:22
问题 I am attempting to perform a bulk-insert using Dapper over Npgsql, that returns the ids of the newly inserted rows. The following insert statement is used in both of my examples: var query = "INSERT INTO \"MyTable\" (\"Value\") VALUES (@Value) RETURNING \"ID\""; First, I attempted to add an array of objects with a "Value" property: var values = new[] { new { Value = 0.0 }, new { Value = 0.5 } }; var ids = connection.Query<int>(query, values); However, that fails with the NpgsqlException:

Inserting One to Many Entities using dapper

蓝咒 提交于 2019-12-20 19:47:15
问题 I have following two classes and corresponding db tables. I am trying to insert the full object graph (student with multiple courses). I am looking for an example on how would one do this using Dapper. The Id's are auto-increment identity fields. Class public class Student { public int Id {get;set;} public string Name {get;set;} public IEnumerable<Course> Courses {get;set;} } public class Course { public int Id {get;set;} public string Name {get;set;} } Table Student Id [int] (pk) Name

Custom mapping in Dapper

百般思念 提交于 2019-12-20 12:40:19
问题 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

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

只谈情不闲聊 提交于 2019-12-20 12:05:39
问题 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? 回答1:

Store enum as string in database

♀尐吖头ヾ 提交于 2019-12-20 09:48:39
问题 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? 回答1: 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

What is the difference between how objects are handled in Dapper and Entity Framework - with raw SQL queries?

℡╲_俬逩灬. 提交于 2019-12-20 07:30:02
问题 From my reading, Dapper is suppose to be more SQL friendly, but Entity Framework (EF) allows raw SQL. I typically use SQL, but I like some of the things in EF. Many of my queries are fairly complex, cover more than one database and database engine, and most are not just simple CRUD. When it comes to using SQL, what is the difference in how an object is handled? When I issue a query, if something comes back and I assign it to a <dynamic> List type, are they both the same? I am using ASP.NET