dapper

xUnit test deadlock

爱⌒轻易说出口 提交于 2019-12-11 09:58:47
问题 When I run my xUnit unit tests I sometimes get an error message like "Transaction (Process ID 58) was deadlocked on lock resources with another process and has been chosen as the deadlock victim" on one or more of the tests, seemingly randomly. If I re-run any failing test on its own it passes. What should I do to prevent this? Is there an option to run the tests one-after-another instead of all at once? (N.B. I'm running the tests over the API methods in my ASP.Net 5 MVC controllers under

Dapper source code - will this dispose of my connection properly?

风流意气都作罢 提交于 2019-12-11 05:59:38
问题 Looking at the source code for Dappers QueryAsync method SqlMapper.Async.cs private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn, Type effectiveType, CommandDefinition command) { using (var cmd = command.TrySetupAsyncCommand(cnn, info.ParamReader)) { DbDataReader reader = null; try { if (wasClosed) await cnn.TryOpenAsync(cancel).ConfigureAwait(false); var func = tuple.Func; if (command.Buffered) { var buffer = new List<T>(); var convertToType = Nullable

Dapper can't recognize wildcard param in the single quotes

故事扮演 提交于 2019-12-11 05:18:42
问题 I am trying to get indexes fragmentation info from database. Here the dapper sql query: var result = await _dbConnection.QueryAsync<IndexFragmentationModel>($@" select a.index_id as Id, name as Name, avg_fragmentation_in_percent as FragmentationPercent from sys.dm_db_index_physical_stats (DB_ID(N'@dbName'), OBJECT_ID(N'@tableName'), null, null, null) as a join sys.indexes as b on a.object_id = b.object_id and a.index_id = b.index_id; ", new { dbName = dbName, tableName = tableName }); return

How do I return one-to-many records in a specific order with Dapper and multi-mapping?

自古美人都是妖i 提交于 2019-12-11 04:57:33
问题 From Github: Dapper allows you to map a single row to multiple objects. This is a key feature if you want to avoid extraneous querying and eager load associations. Example: Consider 2 classes: Post and User > class Post { > public int Id { get; set; } > public string Title { get; set; } > public string Content { get; set; } > public User Owner { get; set; } } > > class User { > public int Id { get; set; } > public string Name { get; set; } } Now let us say that we want to map a query that

Dapper Syntax - 2016

故事扮演 提交于 2019-12-11 03:25:07
问题 I'm just beginning my first MVC project using Dapper (and Dapper.Contrib) instead of EF. I'm trying to make sure I'm using the proper syntax when using it. Searching the web, I can see that as Dapper has evolved, so has some of its requirements and syntax. Is there an up to date document that shows best practices for using Dapper in 2016? Specifically, my questions are: Do I need to open and close the connection? It looks like Dapper used to require it but may not any longer. Using Dapper

Using Always Encrypted of SQL Server from .NET Core 2.1

橙三吉。 提交于 2019-12-11 02:48:50
问题 I am aware that Microsoft has not specified any plan to support Always Encrypted from within Core, yet. However, this is supported by classical .NET Framework (4.5 onward). Our Core 2.1 project's usage of Always Encrypted is limited to two simple queries and we are willing to take alternative routes to use it other than downgrading from Core 2.1. There are many remote ways to solve these problems but they involve remoting (WCF or REST for another classical .NET) or through a Service Fabric

Change Dapper so that it maps a database null value to double.NaN

て烟熏妆下的殇ゞ 提交于 2019-12-11 02:05:22
问题 I have a nullable double column in my SQLite database. When reading from the database (for columns of type double) I would like to convert nulls into "double.NaN". Currently dapper sets null values to 0, which I do not want. What are my options? Modify Dapper source code. Can't use Dapper, need to write my own ADO.NET code the old fashioned way? change the way that I call the cnn.Query method, to modify the way that mapping happens. My first choice is option 1, but I need help modifying

Dapper returning a sub set of specific columns directly into DTO

守給你的承諾、 提交于 2019-12-11 01:59:03
问题 Can Dapper return data directly into a DTO/POCO that only has a subset of fields - ie can I it use classes that do not contain all the columns in the db tables? Eg if I have the following query (excuse my sql - not my strong point): select c.Name as "Customer", o.Number as "OrderNo", ol.Number as "Line", p.Description as "Product", ol.Qty from order o join customer c on c.Id = o.CustomerId join orderLine ol on ol.OrderID = o.Id join product p on p.Id = ol.ProductId where o.date >= 1/9/2013

How do I rewrite this to be more LINQy?

假如想象 提交于 2019-12-11 01:46:59
问题 I have this set of data here. Events has a property EventGroups that is of type List<Groups> List<Events> e; List<Groups> g; // Get the data from the database using dapper using( var con = DataAccessMaster.GetOpenConnection( ) ) { using( var multi = con.QueryMultiple( sprocname, new { StartDate = fromDate, EndDate = toDate }, commandType:CommandType.StoredProcedure ) ) { e = multi.Read<Events>( ).ToList( ); g = multi.Read<Groups>().ToList(); } } // Only put the groups that belong to one

Dapper Oracle Number(10,0) is returned as Decimal Parser error

雨燕双飞 提交于 2019-12-10 23:26:38
问题 I have a POCO: public class Role { public Int32 Id { get; set; } public string Name { set; get; } } The Oracle table is Id NUMBER(10,0) and Name VARCHAR2(100 CHAR) Dapper inserts fine but when I read the records it bring the Id as decimal and I get a parser error. And NO, I can't change the Int32 Id to decimal Id in POCO class. 回答1: Thanks to Alex I installed ODP.net and it worked. 来源: https://stackoverflow.com/questions/10000203/dapper-oracle-number10-0-is-returned-as-decimal-parser-error