dapper

Alternative way to get output parameter from stored procedure

北战南征 提交于 2019-11-29 04:27:49
I love using Dapper for my ORM needs but I know there must be a better way to insert/update my sql server database using a stored procedure and strongly typed Lists. For example: I have a class Song: public class Song { public int Id { get; set; } public string title { get; set; } public string genre { get; set; } } and somebody submits a List of songs: List<Song> songs = new List<Song> { new Song { Id = 1, title = "Song 1" , genre="rock"}, new Song { Id = 2, title = "Song 2" , genre="disco"}}; I want to update the database using my stored procedure which either inserts the new song or updates

Dapper & MS Access - Read works, Write doesn't

谁说胖子不能爱 提交于 2019-11-29 04:08:51
Let's start by getting this out of the way: I'm stuck using an MS Access DB and I can't change it. This works fine: using (OleDbConnection conn = ConnectionHelper.GetConnection()) { conn.Open(); var results = conn.Query<string>( "select FirstName from Students where LastName = @lastName", new { lastName= "Smith" } ); conn.Close(); } This works fine: using (OleDbConnection conn = ConnectionHelper.GetConnection()) { OleDbCommand cmd = new OleDbCommand( "update Students set FirstName = @firstName, City = @city where LastName = @lastName", conn ); cmd.Parameters.AddWithValue("firstName", "John");

Is there a way to access the columns in a Dapper FastExpando via string or index?

岁酱吖の 提交于 2019-11-29 02:00:35
问题 I am pulling in a Dapper FastExpando object and want to be able to reference the column names dynamically at run time rather than at design/compile time. So I want to be able to do the following: var testdata = conn.Query("select * from Ride Where RiderNum = 21457"); I want to be able to do the following: foreach( var row in testdata) { var Value = row["PropertyA"]; } I understand that I can do: var Value = row.PropertyA; but I can't do that since the name of the property i'm going to need

Can AnsiStrings be used by default with Dapper?

旧城冷巷雨未停 提交于 2019-11-29 01:44:36
I'm using Dapper against a database where strings are stored primarily in VarChar columns. By default Dapper uses NVarChar parameters when generating queries and while I can wrap each and every string parameter I use with DbString it'd be great to use AnsiStrings by default and use DbString for the NVarChar case. I tried changing the type map in the Dapper source from DbType.String to DbType.AnsiString however that seems to cause an error in the IL generation for the parameters delegate (throws an InvalidProgramException ). Is there an easier way to do this? Update Just changing the typeMap

Is it possible to declare an anonymous type in C# with a variable/dynamic set of fields?

时光怂恿深爱的人放手 提交于 2019-11-29 01:36:28
问题 In C#, I would like to figure out if it's possible to declare an anonymous type where the fields are not known until run-time. For example, if I have a List of key/value pairs, can I declare an anonymous type based on the contents of that list? The specific case I'm working with is passing parameters to Dapper, where I don't know ahead of time how many parameters I will have. List<Tuple<string, string>> paramList = new List<Tuple<string, string>>() { new Tuple<string, string>("key1", "value1"

Why should one use Dapper ? Also can anyone comment on Dapper Vs ADO.NET Pros and Cons [closed]

帅比萌擦擦* 提交于 2019-11-28 22:18:23
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I would like to understand on when would some one really need to think of using Dapper. Also i would like to understand the Pros and Cons of comparing Dapper Vs ADO.NET 回答1: Dapper is just a tool. What it does is: make it trivially easy to correctly parameterize queries make it trivially easy to execute queries

Any good samples for getting started with Dapper? [closed]

徘徊边缘 提交于 2019-11-28 19:48:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm trying to get started with Dapper in an exisiting MVC3 project and although it looks very easy to use, I can't seem to find any tutorials on how to set it up intially. Any links or suggestions would be highly appreciated. Thanks a lot. 回答1: That is, in part, because there is nothing to set up - all you need

Dapper and anonymous Types

血红的双手。 提交于 2019-11-28 19:11:34
Is it possible to use anonymous types with Dapper? I can see how you can use dynamic i.e. connection.Query<dynamic>(blah, blah, blah) is it then possible to do a .Select(p=> new { A, B ,C }) or some variation of that afterwards? Edit I thought I'd show you how I am using Dapper at the moment. I tend to cache (using an InMemoryCache) data so I just do one big query at the beginning (which is super quick using Dapper) then I use Linq to sort it all out in my Repository. using System; using System.Collections.Generic; using System.Configuration; using System.Data.Common; using System.Linq; using

How to return dynamic types List<dynamic> with Dapper ORM

安稳与你 提交于 2019-11-28 19:10:56
I have been using Dapper.net for a while now and its a very good ORM mapper which works great with .Net dynamic types. But I noticed that when Dapper retrieves data from a database it returns as DapperRow type. Is there are any way that I can return it in any other type Like System.Dynamic.ExpandoObject ? Marc Gravell The DapperRow object is designed to share a lot of state between rows. For example, if you fetch 40 rows, the column names etc are only stored once . If we used ExpandoObject , this would need to be configured per row. Hence, the use of DapperRow as the behind-the-scenes

How to generate model from database using Dapper?

人走茶凉 提交于 2019-11-28 17:19:38
I am coming from PetaPoco camp. PetaPoco has a T4 template which generates model from the database. Is anything similar available for Dapper? I installed Dapper using NuGet and added SqlHelper.cs, but I didn't find anything which generates model from the database. Void Ray Dapper itself provides few extension methods (Query, Execute) for the connection object and does not have "model generator." Perhaps some other framework can be used to generate POCO's based on the db schema. Update: Database tables to C# POCO classes T4 template <#@ template language="C#" debug="True" #> <#@ assembly name=