dapper

Which transaction is better with Dapper: BEGIN TRAN or TransactionScope?

白昼怎懂夜的黑 提交于 2019-12-09 22:33:07
问题 I've just started using Dapper and I was wondering which pattern for transactions would be better. When I write SQL I prefer to use the transaction already in the script with: BEGIN TRAN -- insert, update etc. COMMIT because it's easier to test it but there is also the question transaction with dapper dot net where .net transactions are used so now I'm not sure which one I should actually use. Does either method have any dis/advantages over the other? 回答1: Actually, this has nothing to do

Dapper type mapping hangs in Windows 10 for large queries

与世无争的帅哥 提交于 2019-12-09 19:00:38
问题 I have a very simply query in my projects that returns ~1.3 million rows: var aliases = ctx.Query<sec_entity_alias>(@"select * from sec_entity_alias"); The class that is mapped to is: public partial class sec_entity_alias { public int id { get; set; } public int sec_entity_id { get; set; } public byte sec_entity_alias_type_id { get; set; } public string symbol { get; set; } public virtual sec_entity_alias_type sec_entity_alias_type { get; set; } } When I run the query it hangs indefinitely

How do I use Dapper to get the return value of stored proc?

删除回忆录丶 提交于 2019-12-09 16:40:46
问题 I'm using Dapper in asp.net mvc 4 project .net f/w 4.6.1 using sql server 2016 express <packages> <package id="Dapper" version="1.50.2" targetFramework="net461" /> </packages> I have a stored proc which deletes from 2 tables which should be transactional ALTER PROCEDURE [dbo].[FeedbackDelete] @FeedbackID UNIQUEIDENTIFIER AS SET NOCOUNT OFF SET XACT_ABORT ON BEGIN TRANSACTION DELETE FROM dbo.Document WHERE FeedbackId = @FeedbackID IF(@@ERROR != 0) BEGIN ROLLBACK TRANSACTION RETURN 1 END DELETE

Dapper Multi Mapping with QueryMultiple

二次信任 提交于 2019-12-09 14:29:21
问题 I have a stored procedure that returns multiple result sets. I'm executing this with dapper. One of the result sets is Person JOIN Checks, where Person can have many Checks. The end goal is to have distinct person objects that have a collection of check objects. QueryMutliple gives me a Sqlmapper.GridReader . I see an overload of SqlMapper.GridReader.Read() that takes a Func<TFirst, TSecond, TReturn> . Is there an example of how to use this? 回答1: Here's how I got it working: var q =

Authentication and Authorization without Entity Framework in ASP.NET 5 MVC 6

假如想象 提交于 2019-12-09 08:41:20
问题 I'm trying to configure my authentication and authorization using my existing database and tables, without using Entity Framework (using Dapper). I've got the Dapper configured correctly, now I'm trying to hook up the SignInManager, and UserManager to call my database via Dapper, but before that can happen, I'm running into some errors with my custom role store. Here's the error that I'm receiving when I click the "Register" button on the website (this is just a plain project with all of the

Where to put sql when using dapper?

烂漫一生 提交于 2019-12-09 05:14:19
问题 I'm using dapper for a mvc3 project at work, and I like it. However, how are you supposed to layer the application when using dapper? Currently I just have all my sql stuffed directly in the controller ( slap ) but I was thinking of making a class with static strings.. So I could do var reports = Dapper.Query<Report>(conn, MySql.ReportsRunningQuery) How do you store your sql when using dapper? 回答1: I would say put the sql where you would have put the equivalent LINQ query, or the sql for

How do I use 'Where In' in Dapper

不想你离开。 提交于 2019-12-09 05:04:56
问题 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

What does the buffered parameter do in Dapper dot net?

血红的双手。 提交于 2019-12-09 04:17:34
问题 Dapper dot net has a buffer parameter (a bool), but as far as I can tell the only thing it does is cast the result to a list before returning it. As per the documentation: Dapper's default behavior is to execute your sql and buffer the entire reader on return. This is ideal in most cases as it minimizes shared locks in the db and cuts down on db network time. However when executing huge queries you may need to minimize memory footprint and only load objects as needed. To do so pass, buffered:

Dapper AddDynamicParams for IN query with IEnumerable parameter in Postgres

只谈情不闲聊 提交于 2019-12-08 22:02:41
问题 To start, I am having the same problem that was discussed, and allegedly fixed about two years ago. See the following question for that issue: Dapper AddDynamicParams for IN statement with "dynamic" parameter name The problem that I am experiencing is that when I perform a similar query ( SELECT * FROM MyTable WHERE MyId IN @myIds ) against my Postgres 9.3 database, I am getting the following exception: Npgsql.NpgsqlException : ERROR: 42883: operator does not exist: integer = integer[] My

NullReferenceException when inserting with Dapper

让人想犯罪 __ 提交于 2019-12-08 19:30:19
问题 When I run the following code I get a NullReferenceException saying that an object reference not set to an instance of the object. I've successfully inserted with dapper using less complex objects but the same format, so am not sure what I'm doing wrong. public void Foo(IEnumerable<FogbugzCase> cases) { // using a singleton for the SqlConnection using (SqlConnection conn = CreateConnection()) { foreach (FogbugzCase fogbugzCase in cases) { conn.Execute("INSERT INTO fogbugz.Cases(CaseId, Title,