dapper

Using Dapper QueryMultiple in Oracle

不问归期 提交于 2019-12-02 19:24:11
I´m trying to use dapper with Oracle (ODP.NET) and I would like to use the "QueryMultiple" functionality. Passing this string to the QueryMultiple method: var query = "Select CUST_ID CustId from Customer_info WHERE CUST_ID=:custId;" + "Select CUST_ID CustId from BCR WHERE CUST_ID=:custId"; I´m getting a ORA-00911: invalid character error Is there any way to do this or it´s not possible? Tks The OP has probably long since solved the issue by now, but as of the time of writing, this question has only one answer and it doesn't really solve the problem of using Dapper's QueryMultiple() method with

dapper之连接数据库(Oracle,SQL Server,MySql)

拜拜、爱过 提交于 2019-12-02 18:58:01
  因为项目需求,需要项目同时可以访问三个数据库,因此本人经过一番研究,得出以下代码。    1.建立公共连接抽象类(DataBase) 1 public abstract class DataBase 2 { 3 /// <summary> 4 /// 5 /// </summary> 6 public abstract string ConnectionString { get; } 7 8 /// <summary> 9 /// 10 /// </summary> 11 /// <param name="cmd"></param> 12 /// <param name="pName"></param> 13 /// <param name="value"></param> 14 /// <param name="type"></param> 15 /// <returns></returns> 16 17 public DbParameter CreateParameter(DbCommand cmd, String pName, Object value, System.Data.DbType type) 18 { 19 var p = cmd.CreateParameter(); 20 p.ParameterName = pName; 21 p.Value =

dotnetcore中使用dapper

我的未来我决定 提交于 2019-12-02 18:28:47
  我们都知道,ORM全称是,Object Relationship Mapper,即,对象关系映射。也就是可以用object来map我们的db,而且市面上的orm框架有很多,其中有一个框架叫做dapper,而且被称为the king of ORM。   市场上,也有一些其他的ORM,比如EF Core,NHibernate ,来处理大数据访问及关系映射。既然官方推出了EF Core,说明其对框架的支持会很友好,为什么又会有那么多的ORM框架供我们使用呢?其实,每一个框架都有其适用的场景。如果你在小的项目中,使用Entity Framework、Entity Framework Core、NHibernate 来处理大数据访问及关系映射,未免有点杀鸡用牛刀。你又觉得ORM省时省力,这时Dapper 将是你不二的选择。其实,Entity Framework Core的性能并不是很高,当对性能有要求的时候,一般公司都会自己封装一套ORM。 为什么选择Dapper? 轻量。只有一个文件( SqlMapper.cs ),编译完成之后只有120k(好象是变胖了) 速度快。Dapper的速度接近与IDataReader,取列表的数据超过了DataTable。 支持多种数据库。Dapper可以在所有Ado.net Providers下工作,包括sqlite, sqlce, firebird,

Dapper multiple objects from one row

天大地大妈咪最大 提交于 2019-12-02 18:25:14
I have one row coming from the database select "John" Name, "Male" Gender, 20 Age, "Rex" PetName, "Male" PetGender, 5 PetAge // ... many more ... Using Dapper, I'd like to pull this row into two objects: class Person { public string Name { get; set; } public string Gender { get; set; } public int Age { get; set; } // ... many more ... } class Pet { public string PetName { get; set; } public string PetGender { get; set; } public int PetAge { get; set; } // ... many more ... } Note: there is no hierarchical relationship here, I'm simply trying to map one database row into two (or more) objects.

Using Async Await keywords with Dapper

我的梦境 提交于 2019-12-02 17:39:42
I want to use a micro-orm and decided to go with Dapper. But can't seem to find any mentions of it supporting the new async/await syntax. Async queries are important for me. Can someone provide a code example of an async query being made with Dapper using the await keyword ? Dapper when targeting .NET 4.5 has full support for TPL usage, via the methods ending in *Async - QueryAsync etc. Specifically, the .NET 4.5 build includes this extra set of methods Here's a sample Yaron public async Task<List<Artist>> GetAllAsync() { using ( SqlConnection conn = new SqlConnection(Conn.String)) { await

Dapper with Attributes mapping

北城余情 提交于 2019-12-02 15:18:39
I try to map my Id fields with the Column Attributes but for some reason this doesn't seem to work and I can't figure out why. I set up a test project to demonstrate what I am trying. First, I got my 2 entities: Entity Table1 using System.Data.Linq.Mapping; namespace DapperTestProj { public class Table1 { [Column(Name = "Table1Id")] public int Id { get; set; } public string Column1 { get; set; } public string Column2 { get; set; } public Table2 Table2 { get; set; } public Table1() { Table2 = new Table2(); } } } and entity Table2 using System.Data.Linq.Mapping; namespace DapperTestProj { public

Java Micro ORM equivalent [closed]

痴心易碎 提交于 2019-12-02 14:16:50
What would be the closest equivalent in Java to a Micro ORM such as Dapper , PetaPoco , Massive or CodingHorror ? I recommend Spring JDBC templates . While it's not a "true" ORM, it's a pleasure to use where Hibernate seems to be an overkill. sql2o seems like a Dapper alternative - thin wrapper around JDBC String sql = "SELECT id, category, duedate " + "FROM tasks " + "WHERE category = :category"; Sql2o sql2o = new Sql2o(DB_URL, USER, PASS); List<Task> tasks = sql2o.createQuery(sql) .addParameter("category", "foo") .executeAndFetch(Task.class); github - https://github.com/aaberg/sql2o site -

Using Dapper, how do I pass in the values for a sql type as param?

北城以北 提交于 2019-12-02 10:25:18
I'm attempting to use dapper and pass into a stored procedure a list of integers which I have defined here using DDL CREATE TYPE [dbo].[BrandIDSet] AS TABLE ([BrandID] INT NULL); I've created this stored procedure: CREATE PROCEDURE dbo.usp_getFilteredCatalogItems @BrandIDSet [dbo].[BrandIDSet] READONLY and attempting to pass in in c# code the value for that parameter as public async Task<PaginatedCatalogItemsVM> GetFilteredCatalogItems(int pageSize, int pageNumber, List<int> brandIDSet) { .. string storedProcName = "dbo.usp_getFilteredCatalogItems"; paginatedItemsVM.CatalogItemResults = await

What is the difference between how objects are handled in Dapper and Entity Framework - with raw SQL queries?

回眸只為那壹抹淺笑 提交于 2019-12-02 09:58:06
From my reading, Dapper is suppose to be more SQL friendly, but Entity Framework (EF) allows raw SQL. I typically use SQL, but I like some of the things in EF. Many of my queries are fairly complex, cover more than one database and database engine, and most are not just simple CRUD. When it comes to using SQL, what is the difference in how an object is handled? When I issue a query, if something comes back and I assign it to a <dynamic> List type, are they both the same? I am using ASP.NET Core 1.x. If you're using EF to issue SQL requests, you're not really using EF. The calls are line for

Dapper parameters not working with PostgreSQL through npgsql connection, is postgres anonymous function parameterization supported?

二次信任 提交于 2019-12-02 07:22:11
问题 I'm trying to use dapper to parameterize a postgres anonymous function i've written to do an upsert. Here's the code: private static int UpsertProductPrice( IDbConnection connection, Data.ProductPrice price, List<Data.ProductPriceTier> priceTiers) { string postgres = @"DO $$ BEGIN UPDATE product_price SET start_date = @StartDate, end_date = @EndDate, price_tier_type = @PriceTierType WHERE product_price_external_id = @Id; IF found THEN RETURN; END IF; BEGIN INSERT INTO product_price(product