dapper

Dapper & Oracle Clob type

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using dapper to do some oracle access. I have a scenario where I have to have an output parameter with a type of OracleDbType.Clob. As I am using dapper and thus using the base DbType enumeration I am using the DbType.Object enum as suggested here http://docs.oracle.com/html/B14164_01/featOraCommand.htm to stand in for OracleDbType.Clob. However, this sets the command parameter (deep down in dapper) to be of DbType object and oracle type Blob (as the DbConnection providers a concrete OracleParameter). The problem being this Oracle proc

dapper -multi-mapping: flat sql return to nested objects

…衆ロ難τιáo~ 提交于 2019-12-03 08:37:40
问题 I have a company that contains an address object. The SQL return is flat, and I'm tring to get Query<> to load all the objects. cnn.Query<Company,Mailing,Physical,Company>("Sproc", (org,mail,phy) => { org.Mailing = mail; org.Physical = phy; return org; }, new { ListOfPartyId = stringList }, null, true, commandTimeout: null, commandType: CommandType.StoredProcedure, splitOn: "MailingId,PhyscialId").ToList(); I'm not sure if i have the SplitOn correct either. I'm getting the message: When using

How to get Dapper to ignore/remove underscores in field names when mapping?

空扰寡人 提交于 2019-12-03 08:26:56
问题 There are many ways to map database field names to class names, but what is the simplest way to just remove the underscores? public IEnumerable<PersonResult> GetPerson(int personId) { using (var dbConnection = _dbConnectionFactory.Create(ConnectionStrings.ProjectXYZ)) { IEnumerable<PersonResult> result = dbConnection.Query<PersonResult>("fn_get_person", new { personId }, commandType: CommandType.StoredProcedure).ToList(); return result; } } Table and database fields: person -------- person_id

Fastest way to map result of SqlDataReader to object

寵の児 提交于 2019-12-03 07:29:31
I'm comparing materialize time between Dapper and ADO.NET and Dapper. Ultimately, Dapper tend to faster than ADO.NET, though the first time a given fetch query was executed is slower than ADO.NET. a few result show that Dapper a little bit faster than ADO.NET(almost all of result show that it comparable though) So I think I'm using inefficient approach to map result of SqlDataReader to object. This is my code var sql = "SELECT * FROM Sales.SalesOrderHeader WHERE SalesOrderID = @Id"; var conn = new SqlConnection(ConnectionString); var stopWatch = new Stopwatch(); try { conn.Open(); var sqlCmd =

Using Dapper QueryMultiple in Oracle

 ̄綄美尐妖づ 提交于 2019-12-03 06:50:00
问题 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 回答1: The OP has probably long since solved the issue by now, but as of the time of writing, this

Using Dapper to populate Enum properties

╄→гoц情女王★ 提交于 2019-12-03 06:36:35
问题 In using Dapper's Query() function, I am trying to fill in a class that has a property which is an enumerated value. In my database, this column is stored as a byte. However, in the class, they are an enum. In the old ADO.NET approach, I'd convert during the reader loop: myClass.myEnum = (MyEnumType) reader.GetByte(2); When using Dapper, I can't figure out how to do this conversion. For example when I do something like myClass = conn.Query<MyClassType>("SELECT ... ") I get an error of the

Unit Testing Dapper with Inline Queries

强颜欢笑 提交于 2019-12-03 05:59:21
问题 I know there are several question similar to mine. Dapper: Unit Testing SQL Queries Testing Dapper Queries butI don't think both of above question has clear answer that fit my requirement. Right now I develop a new WebAPI project and split between WebAPI project and DataAccess technology. I not have a problem test the Controller for WebAPI since I can mock the data access class. But for DataAccess class that's a different stories, since I'm using Dapper with inline queries in it, I'm a bit

Repository vs Service pattern in DAL: EF and Dapper

断了今生、忘了曾经 提交于 2019-12-03 05:11:52
问题 I'm working on project and I need to design the DAL. I will be using Entity Framework for most of the project and Dapper for some performance-sensitive areas. I was thinking about using the Repository pattern but then EF already implements this pattern in some sense. But that's not the case with Dapper. Then I am wondering is it valid to mix Repository and Service patterns in my DAL? Or would this be crossing into the Business Logic Layer? A sample structure I was thinking to buid:

Dapper multiple objects from one row

雨燕双飞 提交于 2019-12-03 05:08:59
问题 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

Dapper MultiMap doesn't work with splitOn with NULL value

独自空忆成欢 提交于 2019-12-03 05:07:14
I have a problem with MultiMaps in dapper trying to split on column that contains NULL . Dapper seems not to instantiate object and my mapping function receives null instead of object. Here's my new test: class Product { public int Id { get; set; } public string Name { get; set; } public Category Category { get; set; } } class Category { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } } public void TestMultiMapWithSplitWithNullValue() { var sql = @"select 1 as id, 'abc' as name, NULL as description, 'def' as name"; var product = connection