dapper

Trying to set up a Dapper-based Data Access Layer. ABP.Dapper documentation is confusing and incomplete

纵饮孤独 提交于 2019-12-25 02:15:57
问题 I'm trying to set up a simple DAL that will return a List of typed objects. Pretty standard data repository stuff. I downloaded all of ABP's code from GitHub, built the DLLs for Abp.Dapper and Abp.EntityFrameworkCore and started following the instructions on this page: https://aspnetboilerplate.com/Pages/Documents/Dapper-Integration But I can't even get past step one of this. This code doesn't compile because it doesn't know what SampleApplicationModule is. But there's no guidance in these

Dapper.Contrib Insert Exception

≯℡__Kan透↙ 提交于 2019-12-24 18:40:42
问题 On asp.net core application when i execute insert operating application throws error. previously application was asp.net core 1.1 recently i updated to asp.net core 2.0 using (var con = _connectionFactory.CreateConnection()) { con.Open(); using (var transaction = con.BeginTransaction()) { try { if (regions.Any()) { con.Insert(regions.Select(c => { c.UserId = userId; return c; }), transaction); } transaction.Commit(); } catch(Exception exception) { transaction.Rollback(); } } } exception was

NotSupportedException when inserting with Dapper

你离开我真会死。 提交于 2019-12-24 13:29:35
问题 I'm trying to insert a bunch of fogbugz cases into my own database but get a NotSupportedException: The member OutlineUri of type System.Uri cannot be used as a parameter value. By creating args before passing it in I was able to ensure that I'm not referencing a null object (from this SO question). I can see that fogbugzCase.OutlineUri has a valid value when the exception is thrown. Any ideas? Here's the code (apologies about lots of indentation): public void Foo(IEnumerable<FogbugzCase>

Pass C# bool as parameter to Oracle using Dapper

纵然是瞬间 提交于 2019-12-24 09:49:06
问题 I'm trying to pass a bool as a parameter to Oracle using Dapper, translating to a 1/0 field on the database, like this: public class Customer { public bool Active { get; set; } } static void InsertCustomer() { var customer = connect.QueryFirst<Customer>("select 1 active from dual"); // this works connect.Execute("insert into customers(active) values(:active)", customer); // this doesn't } But this throws an exception: System.ArgumentException: 'Value does not fall within the expected range.'

Reading subset of the table using Dapper in C#

时光怂恿深爱的人放手 提交于 2019-12-24 08:53:41
问题 I am using Dapper in the project, and it's ok if I need to get either the single primitive type (int, decimal, string, etc) or any db entity, but I need to read just 2 columns from the table, and I faced with lots of the challenges here: This is a simple query: SELECT col1, col2 FROM Table1 Where I expect to receive string and int And this is how I read the data once the query is implemented: var field1 = (await result.ReadAsync<string, int>()).FirstOrDefault(); And this is not compilable. I

Dapper not running Async together with Devart oracle driver

时光毁灭记忆、已成空白 提交于 2019-12-24 07:36:03
问题 I have a repository method in a ASP WebApi site public async Task<IEnumerable<Animal>> GetAnimals(List<long> herdIds) { using (var sqlConnection = new OracleConnection(Connectionstring)) { await sqlConnection.OpenAsync(); var sql = GetCommonSqlQuery(herdIds, true); var result = await sqlConnection.QueryAsync<Prop1, Prop2, Prop3, Prop1>( sql, (a, g, b) => { a.Prop2 = g; a.Prop3= b; return a; }); return result; } } I use that with Task<IEnumerable<Animal>> animalsTask = animalsRepository

named parameters in sp_executesql

坚强是说给别人听的谎言 提交于 2019-12-24 02:23:08
问题 is there any way that you can call sp_executesql with parameters that don't depend in the order they are defined in the store? the same query with exec works well, and if you have the same order it also works well, but it's a pain having to match the parameter one by one, because sometime I am generatin the call dynamically with helpers, and if the dto object don't have the same fields in the same order, doesn't work well. create procedure ordertest @PARAM1 INT, @PARAM2 INT AS BEGIN SELECT

How to pass multiple records to update with one sql statement in Dapper

六眼飞鱼酱① 提交于 2019-12-24 01:38:27
问题 I am attempting to use one single Update statement to update multiple records with different values (I'm not trying to update many rows to have the same values which is pretty straight forward). Here's what I'm trying right now: using (var cn = GetOpenConnection()) { // get items where we need to set calculated fields that will now be persisted in the DB var items = cn.Query<MaintenanceItem>("select TOP 500 * from [Maintenance] where Tolerance IS NOT NULL"); foreach (var mi in maintItems) { /

How to pass multiple records to update with one sql statement in Dapper

萝らか妹 提交于 2019-12-24 01:38:01
问题 I am attempting to use one single Update statement to update multiple records with different values (I'm not trying to update many rows to have the same values which is pretty straight forward). Here's what I'm trying right now: using (var cn = GetOpenConnection()) { // get items where we need to set calculated fields that will now be persisted in the DB var items = cn.Query<MaintenanceItem>("select TOP 500 * from [Maintenance] where Tolerance IS NOT NULL"); foreach (var mi in maintItems) { /

Dapper is throwing System.Data.SqlClient.SqlConnection exception after upgrading System.Data.SqlClient to version 4.5.0-preview2

三世轮回 提交于 2019-12-24 00:38:04
问题 I recently upgraded one of my ASP.NET Core applications from a net461 app to ASP.NET Core 2.0 app since the only thing that was holding me back in the past was System.Transactions (which is now supported). After upgrading I get an error when accessing any function that is using the following: protected static TransactionScope GetTransactionScope() { TransactionOptions transactionOptions = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted, Timeout =