dapper

Dapper WHERE IN statement with ODBC

心已入冬 提交于 2019-12-02 07:11:32
问题 I am using Dapper on ODBC provider, which as known does not support named parameters. For most of my queries I used pseudo named parameters: ?name? . However, when I try to string query = $"select * from \"{TableName}\" where ID in ?Ids?"; return connection.Query<CdfGroupByCdfUserRecord>(query, new {Ids = ids}).ToArray(); I see that Dapper generates query select * from "MY_TABLE" where ID in (?Ids1,?Ids2,?Ids3,?Ids4,?Ids5)? What should I do to get it work? 回答1: This appears to be a bug in

Dapper WHERE IN statement with ODBC

流过昼夜 提交于 2019-12-02 06:59:48
I am using Dapper on ODBC provider, which as known does not support named parameters. For most of my queries I used pseudo named parameters: ?name? . However, when I try to string query = $"select * from \"{TableName}\" where ID in ?Ids?"; return connection.Query<CdfGroupByCdfUserRecord>(query, new {Ids = ids}).ToArray(); I see that Dapper generates query select * from "MY_TABLE" where ID in (?Ids1,?Ids2,?Ids3,?Ids4,?Ids5)? What should I do to get it work? This appears to be a bug in dapper. I'll try to fix it for 1.50.2. I've logged it (for tracking purposes) here 来源: https://stackoverflow

Create a DbContext that handle a DatabaseFactory to use DapperExtensions more easily

亡梦爱人 提交于 2019-12-02 06:23:58
This days I try to create an abstract base repository using some basic CRUD functions proposed by DapperExtensions . But the code given as an exemple use a SqlConnection which is made to connect to a SQL Server database. I want to be able to connect to all kind of Database (SQL Server, MySql, etc...). Also their code sample is repeated for each CRUD function as the code below show using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); //Code doing something here... cn.Close(); } So i was thinking about to create a DbContext that can handle the creation, the opening and

Illegal attempt to use Text/Byte host variable - Inserting into TEXT column

Deadly 提交于 2019-12-02 05:29:51
Trying to insert into a table (Text Column) via Dapper, and getting the error from Informix: Illegal attempt to use Text/Byte host variable I have written a small program to simulate this, and I am still up against problems. We cannot currently use the Informix drivers, as they do not suit our needs. using Dapper; using System; using System.Data.Odbc; namespace DapperParamsTest { class Program { static void Main(string[] args) { OdbcConnection conn = new System.Data.Odbc.OdbcConnection("Driver={IBM INFORMIX ODBC DRIVER (64-bit)}; Host=bylgia; Server=bylgia; Service=sqlexec; Protocol=onsoctcp;

How do I map multiple lists with dapper

你。 提交于 2019-12-02 03:09:47
I've got three classes User, Order & Project which are stored in single tables. The orders and projects both have a n:n relation with the users. To implement that I've got two crosstables (UserOrders, UserProjects) which map these relations. public class User { public string UserID {get;set;} public List<string> Orders{get;set;} public List<string> Projects {get;set;} } public class Order { public string OrderID {get;set} ... } public class Project { public string ProjectID {get;set} ... } As you can see the User object contains a list of every related orderID/projectID. Now I want to query

Dapper: Execute a command multiple times and linq and ToArray

南笙酒味 提交于 2019-12-02 01:56:16
According to the dapper docs one can write connection.Execute(@"insert into MyTable(colA, colB) values (@a, @b)", new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } } ) I tried using conn.Execute( @" insert into RelRoleUser ( RoleID, UserID ) values( @roleID, @userID )", userroleList.Select(r => new { roleID = r.roleID, userID = r.userID }).ToArray(), null, null, null); But get an exception "Invalid type owner for DynamicMethod" in Dapper code private static Action<IDbCommand, object> CreateParamInfoGenerator(Type type) { var dm = new DynamicMethod(string.Format("ParamInfo{0}", Guid

Dapper + MSAccess: How to get identifier of inserted row

眉间皱痕 提交于 2019-12-02 00:55:15
问题 I am using Dapper with C# and back end is MS Access. My DAL method inserts record in database. I want to return unique identifier (or updated POCO with unique identifier) of the inserted row. I am expecting my function something like follows (I know this does not work; just to explain what I want): - public MyPoco Insert(MyPoco myPoco) { sql = @"INSERT INTO MyTable (Field1, Field2) VALUES (@Field1, @Field2)"; var param = GetMappedParams(myPoco);//ID property here is null. var result =

.NET Core API后台架构搭建

我怕爱的太早我们不能终老 提交于 2019-12-01 23:51:32
ASP.NET Core API后台架构搭建 项目文件:https://files.cnblogs.com/files/ZM191018/WebAPI.zip 本篇可以了解到: 依赖注入 Dapper ORM框架 第一步:目录文件构建 新建两个类库: 添加好之后,文件构建如下: 第二步:下载Oracle.ManagerDataAccess.Core、Dapper程序包。 第三步:开发DB connection l 新建接口IConnectionProvider、IDbContext。IDbContext实现IDisposable。 l ConnectionProvider、DbContext分别实现接口IConnectionProvider、IDbContext l 再新建一个DbConnectionObj类。因为是使用Dapper ORM框架,因此需要提供一个IDbConnection对象。也就是说,这个类用来提供IDbConnection对象的。 完成DB connection的开发。 对于为什么要将connectionProvider单独拿出来,是因为如果更改使用不同数据库,那么改动该类即可。用途就体现出来了。 第四步:根据数据库表,编写Model。 第五步:开发Table Repository。也就是定义方法使用Dapper操作数据库进行数据的增删改查。 l

Why is Dapper unable to return multiple inserted row ids?

三世轮回 提交于 2019-12-01 22:16:38
I have a SQL Server table into which rows are inserted using: var sql = @" DECLARE @InsertedRows AS TABLE (Id BIGINT); INSERT INTO Person ([Name], [Age]) OUTPUT Inserted.Id INTO @InsertedRows VALUES (@Name, @Age); SELECT Id FROM @InsertedRows;"; Person person = ...; var id = connection.Query<long>(sql, person).First(); This all works well however if I try to insert multiple items and return all the inserted ids using: IEnumerable<Person> people = ...; var ids = connection.Query<long>(sql, people); I get an error: System.InvalidOperationException : An enumerable sequence of parameters (arrays,

Dapper + MSAccess: How to get identifier of inserted row

坚强是说给别人听的谎言 提交于 2019-12-01 20:46:49
I am using Dapper with C# and back end is MS Access. My DAL method inserts record in database. I want to return unique identifier (or updated POCO with unique identifier) of the inserted row. I am expecting my function something like follows (I know this does not work; just to explain what I want): - public MyPoco Insert(MyPoco myPoco) { sql = @"INSERT INTO MyTable (Field1, Field2) VALUES (@Field1, @Field2)"; var param = GetMappedParams(myPoco);//ID property here is null. var result = _connection.Query<MyPoco>(sql, param, null, false, null, CommandType.Text);.Single(); return result;//This