dapper

Ignoring properties in Dapper

你离开我真会死。 提交于 2019-12-30 08:25:32
问题 In Dapper (http://code.google.com/p/dapper-dot-net/), is there a way to ignore properties in the model class, namely when using the Insert extension method? My model class has a set of computed properties which are not persisted in the associated table. Thanks. Pedro 回答1: Well, Dapper has no Insert extension method, that is in dapper.contrib, dapper extensions or dapper rainbow. Dapper itself allows you to do: Animal a = new Animal {Age = 10, Family = "Canine"} // only insert Age cnn.Execute(

How can I make Dapper.NET throw when result set has unmapped columns?

二次信任 提交于 2019-12-30 05:57:06
问题 Using the example code below as context... When I run this query I get the 'Id' field coming back as default value (which is 0 for an int). I would like to tell dapper to run in a manner where it would throw an exception if there is a column in the result set that does not get mapped to a property on my result object. (I understand that the issue is just that I need to remove the extra 'd' in the SQL query but I'm interested in having this expose itself more explicitly) I've been unable to

Why can't I set “this” to a value in C#?

筅森魡賤 提交于 2019-12-29 02:05:48
问题 I am using Dapper.net Extensions and I would like to be able to retrieve a Photo object and set 'this' to it without having to set each property individually. What would be the best way to accomplish this? In the code below it says I cannot assign to 'this' because it is readonly. public class Photo { public Int32 PhotoId { get; set; } public Guid ObjectKey { get; set; } public Int16 Width { get; set; } public Int16 Height { get; set; } public EntityObjectStatus ObjectStatus { get; set; }

Dapper and SQL Injections

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-28 03:46:34
问题 How does Dapper help protect against SQL injections? I am testing out different DAL technologies and have to choose one to be secure our site. I'm leaning towards Dapper (http://code.google.com/p/dapper-dot-net/), but need some help learning about security. 回答1: How does Dapper help protect against SQL injections? It makes it really, really easy to do fully parameterized data access, without ever needing to either concatenate input. In particular, because you don't need to jump through lots

Bulk inserts taking longer than expected using Dapper

点点圈 提交于 2019-12-27 16:49:45
问题 After reading this article I decided to take a closer look at the way I was using Dapper. I ran this code on an empty database var members = new List<Member>(); for (int i = 0; i < 50000; i++) { members.Add(new Member() { Username = i.toString(), IsActive = true }); } using (var scope = new TransactionScope()) { connection.Execute(@" insert Member(Username, IsActive) values(@Username, @IsActive)", members); scope.Complete(); } it took about 20 seconds. That's 2500 inserts/second. Not bad, but

Repository Design Pattern with Dapper

好久不见. 提交于 2019-12-27 11:14:53
问题 This is maybe more a question for code review rather than stack overflow. I am using Dapper for a MicroORM to retrieve and Save Data to SQL Server 2014. I have got DTO classes in a DTO Proj that represent the Data retrieved from the DB or saved to the DB. I am using the Repository Pattern so at my Service layer if a repository is required I am using constructor DI to inject that dependency and then call the method on the Repository to do the work. so let say I have 2 services called

Custom timeout: is there a way to know which line of code was being executed?

北城余情 提交于 2019-12-25 12:54:37
问题 (which line of code is being executed in a binary in production , not in Visual Studio) First a bit of framework for my problem: I have an error that is very difficult to track, because it occurs randomly. In this error, Dapper hangs indefinitely. No timeout exception, no nothing. Just one query that executes indefinitely. Probably a "nasty deadlock case", as Marc Gravell answered in the comments. In order to narrow down where the problem comes from, I created this timeout function: ///

C# change Dapper dynamic to complain if the property doesn't exist

杀马特。学长 韩版系。学妹 提交于 2019-12-25 07:59:20
问题 We're using Dapper to fetch data from our SQL database, which returns our data as a collection of 'dynamic'. I understand the power of dynamic types, and the flexibility of "duck typing", basically "if it quacks like a duck, then it is a duck - I don't need to declare that it's a duck". However, I don't understand why if I try to get a property from a dynamic object that it doesn't have, why doesn't it complain? For example, if I had something that wasn't a duck and I called "Quack" on it, I

Dapper UPDATE not committing to Database before a SELECT is running

六月ゝ 毕业季﹏ 提交于 2019-12-25 07:49:12
问题 I ran into an interesting issue today that I've never seen before. I am using Dapper v1.42.0 inside my MVC app to update records in a SQL database. After the update runs, I am redirecting to an action that selects the same data that was just updated. The issue is, that the SELECT statement is not getting the updated record. It seems like the database hasn't committed the UPDATE before the SELECT is run, but I don't see how that is possible. Here is the code that is called from a client-side

Dapper using ODBC store procedure Input parm always promt @XXX was not supplied

时光怂恿深爱的人放手 提交于 2019-12-25 04:49:09
问题 I need help from All Dapper master. I have been learning using Dapper since one month ago, but I have error when executing query using ODBC SP. The code originally was written by someone(DapperExample) but not using ODBC, thanks to the writer I forgot your name. My SP: CREATE PROCEDURE SP_GET_FIND_EMPLOYEES (@EmpID INT) AS BEGIN SET NOCOUNT ON; SELECT * FROM tblEmployee WHERE EmpID = @EmpID END GO My Code public class EmployeeDashBoard : IEmployeeDashBoard { private IDbConnection _db; string