dapper

Sql CE Inconsistent with Multiple Statements

本小妞迷上赌 提交于 2019-12-10 21:25:06
问题 It has long been true that you can execute multiple statements with SQL CE. And in fact I'm using SQL Server Compact Toolbox to do exactly that. But when I take the same multiple-statement commands and execute them from Dapper... public const string SampleDml = @" INSERT INTO [Plugin](Name, TypeName) VALUES ('Blog','Shroom.Blog'); GO INSERT INTO [ContentDef](PluginID, Name, Placement, IsStatic) VALUES(@@IDENTITY,'MyBlog','Layout:Left',1); GO "; I then keep getting this error: There was an

Dapper Hangs at Execute

假装没事ソ 提交于 2019-12-10 21:04:47
问题 I have an - IDbConnection - sql = @"UPDATE tablename SET json = :json, lastupdate = SYSDATE WHERE id = :id" var param = new DynamicParameters(); param.Add(":json", json, DbType.AnsiString); param.Add(":id", currentTemplate.Id); if (connection == null || connection.State != ConnectionState.Open) continue; connection.Execute(sql, param); // hangs here. connection.Query(sql, param); // tried this and this also hangs. Coding stops at connection.Execute. No error or anything. Just hangs. :json is

Dapper with MS Access Update and Insert issue

[亡魂溺海] 提交于 2019-12-10 20:58:37
问题 I am using Dapper to Update and Insert Access DB. Code is working not throwing exception but its not updating the value in DB. Below is my code sql.Append("UPDATE drugs_repository SET drug_name = @DrugName "); sql.Append(" WHERE id = @DrugId"); var parameters = new { DrugName = objDrug.DrugName, DrugId = objDrug.DrugId }; var t = connection.Query<string>(sql.ToString(), parameters); Can someone please let me know what exactly I am missing in the above code? When I hardcode the value than its

How to use generic and Nullable<T> types in Dapper for materialization?

狂风中的少年 提交于 2019-12-10 20:51:41
问题 I have this call: public IObservable<T> Subscribe(object topic, string service, string connectionString, string query) { try { this.connection.ConnectionString = connectionString; this.connection.Open(); this.connection.Query<T>(query, new { transactionid = topic }).ToObservable().Subscribe(message => this.subject.OnNext(message)); return this.subject; } catch (Exception e) { this.subject.OnError(e); return this.subject; } finally { this.subject.OnCompleted(); this.connection.Close(); } }

Dapper not adding parameters

删除回忆录丶 提交于 2019-12-10 18:45:46
问题 I am trying to use Dapper for our complex queries to remove any lost overhead that was previously existing with NH. I have the following query (note this has been considerably shrunk): SELECT DISTINCT * FROM tasks t WHERE t.initials = @UserInits Which is called via our repository as so: taskRepo.RawExec<TaskListItemDTO>(Query,new {UserInits = "SAS"}) Our implementation of DapperExec consist as follows: public IEnumerable<T> RawExec<T>(string SQL, object param) { return _session.Connection

Dapper insert a list?

此生再无相见时 提交于 2019-12-10 17:45:03
问题 I want to do a bulk insert. A is an ID and B is a list of IDs. My insert statement looks like this but it is wrong. How do I rewrite it to work? The only solution I can think of is using a foreach loop outside the statement .Execute(@"insert into MyTable(a,b) select @a, @b", new {a, b}) 回答1: Try this: var abs = b.Select(id => new { a, b = id }); int numInserted = connection .Execute(@"insert into MyTable(a,b) VALUES(@a, @b)", abs); 来源: https://stackoverflow.com/questions/21209757/dapper

Using named parameter only when passing integer

谁说我不能喝 提交于 2019-12-10 16:47:37
问题 Currently I'm trying to work with Named Parameters using SAP Sybase SQL Anywhere 12 with dapper. The following codes runs correctly: public class Test { public int Str1 { get; set; } public string Str2 { get; set; } } class Program { static void Main(string[] args) { using (SAConnection connection = new SAConnection("...")) { connection.Open(); Test test = connection.Query<Test>("SELECT :Str1 as Str1, :Str2 as Str2", new Test() { Str1 = 35, Str2 = "42" }).FirstOrDefault(); Console.WriteLine($

Dapper: Unit Testing SQL Queries

大兔子大兔子 提交于 2019-12-10 15:52:44
问题 I am starting with Dapper, the micro-ORM, and i use the Dapper Rainbow. I want to test the queries and the data retrieved by them. I mean, for example, i have the UserService with the method GetAll() , and i want to test that the sql query is retrieving all the users from some List (not from the database because i want the tests to be fast). Do you know how can i do that? My service class (and the method i want to test): public static class UserService{ public static IEnumerable<User> GetAll(

Predicate with DapperExtensions

拈花ヽ惹草 提交于 2019-12-10 15:48:31
问题 Im trying to make a generic Find method with DapperExtensions This is my method public IEnumerable<T> Find(Expression<Func<T, object>> expression) { using (IDbConnection cn = GetCn()) { cn.Open(); var predicate = Predicates.Field<T>(expression, Operator.Eq, true); return cn.GetList<T>(predicate); } } But i get System.NullReferenceException on this row var predicate = Predicates.Field<T>(expression, Operator.Eq, true); This is from the DapperExtensions help documentation But I try convert this

How do I escape a '@' in a Dapper query?

和自甴很熟 提交于 2019-12-10 13:46:00
问题 I've got a query that should contain a literal at sign ( @ ). How do I express this with a Dapper query? var num = cnx.Query<int>("declare @foo int = 2; select @foo").Single(); I've tried using literals as a workaround: var num = cnx.Query<int>( "declare {=at}foo int = 2; select {=at}foo", new { at = "@" } ).Single(); But this throws a NotSupportedException since string literals aren't supported... (Note that in my real code, I've got other @parameters that I actually do want replaced and