dapper

Execute stored procedure w/parameters in Dapper

落爺英雄遲暮 提交于 2019-11-29 17:03:58
问题 I'm using Dapper (thanks Sam, great project.) a micro ORM with a DAL and by some reason I'm not able to execute stored procedures with input parameters. In a example service I've the following code: public void GetSomething(int somethingId) { IRepository<Something, SomethingEnum> repository = UnitOfWork.GetRepository<Something, SomethingEnum>(); var param = new DynamicParameters(); param.Add("@somethingId", dbType: DbType.Int32, value:somethingId, direction: ParameterDirection.Input); var

Pulling Apart Expression<Func<T, object>>

北慕城南 提交于 2019-11-29 15:13:10
问题 I am busy creating wrapper extension methods on top of Dapper and DapperExtensions. At the moment I am trying to add filtering to the GetList<T> extension method, similar to LINQ's Where<T> extension method. I have seen this question but it seems I cannot implement what Marc Gravell suggested because there isn't a type EqualsExpression in .NET 4.5. Here is some demo code to help with the explanation of my problem: using System; using System.Collections.Generic; using System.Configuration;

ServiceStack MARS (Multiple Active Result Sets) using ORMLite and Output Parameters

自闭症网瘾萝莉.ら 提交于 2019-11-29 15:12:58
问题 ServiceStack ORMLite is great, I've typically steered clear of the ORM mentality preferring to build databases as it makes sense to build databases instead of a 1:1 class model. That said, there are a couple of things that I seem to be running into difficulty around, I'm certain it's simply my ignorance shining through. First: Is there a way to manage multiple result sets using ORMLite? I know that one can use the QueryMultiple method using Dapper, but for whatever reason I'm having a bear of

Net Core Connection String Dapper visual studio 2017

喜欢而已 提交于 2019-11-29 14:19:37
问题 I am trying to get a Connection String set up in my .Net Core application but i keep getting the error: System.NullReferenceException: 'Object reference not set to an instance of an object.' I have tried adding the following to appsettings.json : "ConnectionStrings": { "Analysis": "Server=DESKTOP-MYSERVER;Database=MYDATABASE;User Id=sa; Password=Password123;Provider=System.Data.SqlClient;Trusted_Connection=True;MultipleActiveResultSets=true;Pooling=false;" } I also tried using web.config like

Dapper intermediate mapping

做~自己de王妃 提交于 2019-11-29 13:34:02
问题 Slightly more advanced mapping then in my previous question :) Tables: create table [Primary] ( Id int not null, CustomerId int not null, CustomerName varchar(60) not null, Date datetime default getdate(), constraint PK_Primary primary key (Id) ) create table Secondary( PrimaryId int not null, Id int not null, Date datetime default getdate(), constraint PK_Secondary primary key (PrimaryId, Id), constraint FK_Secondary_Primary foreign key (PrimaryId) references [Primary] (Id) ) create table

Ignore property on model property

拈花ヽ惹草 提交于 2019-11-29 13:23:05
How can I ignore a property on my model using dapper/dapper extensions/dapper rainbow or any of those dapper libraries? Shiva Dapper creator Sam Saffron has addressed this requirement in response to another SO user's questions here . Check it out. Also, if you want to use the Dapper Extensions library that Sam has mentioned in his answer, you can get it from Github or via Nuget. Here's an example of ignoring properties from the Library's Test Project . using System; using System.Collections.Generic; using DapperExtensions.Mapper; namespace DapperExtensions.Test.Data { public class Person {

Dapper Extension Ms Access System.Data.OleDb.OleDbException

浪尽此生 提交于 2019-11-29 12:52:07
I just started to use Dapper. Dapper works fine. As a next step when I tried to integrate with Dapper Extension. It generates an exception called System.Data.OleDb.OleDbException "Additional information: Characters found after end of SQL statement." Why is that? Dapper Extension doesn't support Ms Access (because of the end character) or problem with my code or I am missing something. My code is below using (var conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myAccessFile.accdb;")) { conn.Open(); conn.Insert<Person>(new Person { Name = "John Stan", Age = 20 }); }

Using Dapper with Oracle

冷暖自知 提交于 2019-11-29 12:29:14
问题 We use Oracle as our database provider and have looked into replacing some of our data access layer (hard to maintain, harder to merge XSD's) with a saner repository based pattern using Dapper at the bottom layer. However, we have hit a number of issues when using it with oracle. Named Parameters: these seem to be ignored, whenever they are used in a query Oracle seems to interpret them in any order it fancies. The SqlMapper returns correctly named parameters, they just aren't interpreted

Is there a way to pass a TVP to dapper on .Net Core right now?

一笑奈何 提交于 2019-11-29 11:25:29
问题 I am using .net core and dapper, the first one doesn't have DataTables and the second one use them for TVP. I was trying to convert a List<T> to a List<SqlDataRecord> , create a SqlParameter with this list and then convert it to a DynamicParameter but sadly I got an: The member of type Microsoft.SqlServer.Server.SqlDataRecord cannot be used as a parameter value UPDATE After playing a bit with IDynamicParameters , I made it work. Extension method for IEnumerable public static DynamicWrapper

ORM之Dapper

こ雲淡風輕ζ 提交于 2019-11-29 11:22:15
一、前言 上一篇【 分层架构设计 】我们已经有了架构的轮廓,现在我们就在这个轮廓里面造轮子。项目要想开始,肯定先得确定ORM框架,目前市面上的ORM框架有很多,对于.net人员来说很容易就想到以ADO.NET为基础所发展出来的ORM框架EntityFramework。不得不说EntityFramework是一个功能很强大的ORM框架,到现在最新的EF分别是EF6(.Net Framework)和EF Core(.Net Core)两个版本。 但是这里我使用的另一个叫Dapper的ORM框架,原因是因为EF太重了,而Dapper是一个轻量级开源的ORM类,他是通过扩展IDbConnection提供一些有用的扩展方法去查询您的数据库,所以Ado.Net支持的数据库,他都可以支持。在速度方面具有“King of Micro ORM”的头衔,几乎与使用原始的ADO.NET数据读取器一样快。第一次使用了他之后,就深深的喜欢上他了。 github地址: https://github.com/StackExchange/Dapper Dapper文档: https://dapper-tutorial.net/dapper 二、Dapper实现 2.1、Dapper的方法 从Dapper文档中,我们知道,Dapper支持一下的方法: Execute :执行一次或多次命令并返回受影响的行数