dapper

Dapper giving “Invalid attempt to call FieldCount when reader is closed.” when trying to use “QueryMultiple”

Deadly 提交于 2019-12-23 09:58:34
问题 I have a wrapper method for Dapper.NET's QueryMultiple method. It successfully gets data from a Stored Procedure, which has 3 queries, all of them are SELECT queries. But after getting the data, I cannot use Read or ReadAsync to assign data to class variables. I'm attaching my code below. public Tuple<IEnumerable<T1>, IEnumerable<T2>, IEnumerable<T3>> QueryMultiple<T1, T2, T3>() { try { var data = MultiQuery("[App].[USP_GetAllCategories]"); var category = data.Read<T1>(); var subcategory =

How to use SqlBuilder

限于喜欢 提交于 2019-12-23 09:06:07
问题 This SqlBuilder: var builder = new SqlBuilder(); var sql = builder.AddTemplate( /*... Intensely dumb question but, how do I use this? I know it's in Dapper.Contrib , but that using statement isn't enough. What references or other using statements do I need to add? 回答1: This question appears in the dapper tutorial page, so I'm updating the answer. In version 1.6, SqlBuilder is in the namespace Dapper . And it is included in the nuget package Dapper.SqlBuilder. This is an example of how it

Dapper multi insert returning inserted objects

烂漫一生 提交于 2019-12-23 07:50:09
问题 Using Dapper I would like to implement a method that takes an IEnumberable of objects of type User . Now, User looks as follows: public class User { public int UserId { get; internal set; } public DateTime DateCreated { get; internal set; } public DateTime DateChanged { get; internal set; } public string Username { get; set; } } The point here is that UserId , DateCreated and DateChanged shall never be set via object, hence the internal keyword. Instead the database will populate these values

Bool type return rule

久未见 提交于 2019-12-23 07:38:37
问题 I use dapper ORM.So i use two rules Query<T> & QuerySingle<T> . Query return the list & QuerySingle return the single object. So,I want to get a bool type. (Actually I wanted to get a bool is true or false record). My Query<T> : public IEnumerable<T> Query<T>(string SqlString) where T : class { return this.conn.Query<T>(SqlString); } So how can I write bool type return? 回答1: So, I want to get a bool type. (Actually I wanted to get a bool is true or false record) You can write a method like

Dapper query with list of parameters

拜拜、爱过 提交于 2019-12-23 07:27:55
问题 I am trying to run a query with Dapper with a known set of parameters, but with a list of values for those parameters. A simple example of what I am trying to do would be: DateTime endDate = DateTime.Now; DateTime startDate = endDate.AddHours(-24); string query = "select COUNT(*) from Test where Status = @Status AND DateCreated <= @Hour;"; var stuff = con.Query(query, (startDate).ByHourTo(endDate).Select(hour => new { Status = 1, Hour = hour, })); Dapper throws an exception with 'Parameter '

Dapper is throwing an invalid cast exception when trying to set a boolean value returned from MySQL

China☆狼群 提交于 2019-12-23 07:19:38
问题 I have this class public class User { public int UserId { get; set; } public string UserName { get; set; } public bool IsValidated { get; set; } } And I'm populating it with this sql using dapper: var users = connection.Query<User>("SELECT userId, userName, TRUE `IsValidated` FROM user WHERE [...]").ToList(); When I run this I get this error: Error parsing column 2 (IsValidated=1 - Int64) I've stepped through the dapper code & the sqldatareader is saying that that column is int64 , so it

Does Dapper work on Mono?

喜欢而已 提交于 2019-12-23 07:12:22
问题 We're thinking about moving over to Mono and I see that Dapper works with MySql. However this is with a ADO.NET provider. Does Mono/Linux have a MySql ADO.NET provider and does that work with Dapper? Eventually we are planning on moving our current site from MySql to PostgreSql and I'm also wondering the same question, but also interms of PostrgreSql, Mono and Dapper on linux? 回答1: I'm using Dapper with the official MySqlConnector on an OpenSuse machine (+ mono) and it works great. 回答2: Why

Dapper - call Oracle schema.package.function

若如初见. 提交于 2019-12-23 05:01:40
问题 I can call Oracle stored procedure and function with Dapper, but I have problems with calling a function inside of package. My error is: ORA-06550: line 1, column 39: PLS-00302: component 'funct' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored My code is : using (IDbConnection cn = Connection) { var a = cn.ExecuteReader(oracleFunctionName, fnParameters, commandType: CommandType.StoredProcedure); } My parameters are ok, but it seems that Dapper can't resolve ORacle

Dapper - call Oracle schema.package.function

自古美人都是妖i 提交于 2019-12-23 05:01:01
问题 I can call Oracle stored procedure and function with Dapper, but I have problems with calling a function inside of package. My error is: ORA-06550: line 1, column 39: PLS-00302: component 'funct' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored My code is : using (IDbConnection cn = Connection) { var a = cn.ExecuteReader(oracleFunctionName, fnParameters, commandType: CommandType.StoredProcedure); } My parameters are ok, but it seems that Dapper can't resolve ORacle

Can't get Dapper to handle SQL RowVersion properly

流过昼夜 提交于 2019-12-23 02:42:10
问题 I've got a rowversion column added to my database and I'm trying to get Dapper mapping to populate it properly on my object. My object has... public byte[] RowVersion { get; set; } And I have included the RowVersion column in my query but when I do a Query.. conn.Query<MyObject, AnotherObject, AnAdditionalObject>(... The MyObject that I get passed to me has a null for the RowVersion property. If I do a Dapper Query() without any type then the dynamic I get back has the expected RowVersion on