dapper

How to remove trailing spaces and change encoding in char(n) columns in dynamic ExecuteQuery

流过昼夜 提交于 2021-02-17 07:07:21
问题 ASP.NET MVC Core 5 application uses Npgsql to get data from Postgres database. Columns in database are defined as CHAR(n) type, like: create table prpalk ( sfirmanimi char(100) ); Column types cannot be changed to varchar. Postgres database encoding is unicode. However some columns are in custom encoding which needs to be converted to unicode to be used in .NET. Those column names in database start always with word Custom. I tried Dapper to get data but data contains trailing spaces and

How to remove trailing spaces and change encoding in char(n) columns in dynamic ExecuteQuery

a 夏天 提交于 2021-02-17 07:06:15
问题 ASP.NET MVC Core 5 application uses Npgsql to get data from Postgres database. Columns in database are defined as CHAR(n) type, like: create table prpalk ( sfirmanimi char(100) ); Column types cannot be changed to varchar. Postgres database encoding is unicode. However some columns are in custom encoding which needs to be converted to unicode to be used in .NET. Those column names in database start always with word Custom. I tried Dapper to get data but data contains trailing spaces and

SmartSql V3 重磅发布

随声附和 提交于 2021-02-15 03:59:08
超轻量级的ORM框架! 107kb 更新内容 移除Dapper依赖 支持存储过程 增强扩展性 重构代码 优化缓存策略 动态实现仓储接口 支持 参数&结果映射 & TypeHandler 高性能 性能测评 BenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134 Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores .NET Core SDK=2.1.201 [Host] : .NET Core 2.0.7 (CoreCLR 4.6.26328.01, CoreFX 4.6.26403.03), 64bit RyuJIT DefaultJob : .NET Core 2.0.7 (CoreCLR 4.6.26328.01, CoreFX 4.6.26403.03), 64bit RyuJIT ORM Type Method Return Mean Error StdDev Rank Gen 0 Gen 1 Gen 2 Allocated Native NativeBenchmarks Query_GetValue_DbNull IEnumerable`1 78.39 ms 0.8935 ms 0.7921 ms 1 3000.0000

Dapper.Contrib: How to get a row by filtering on column other than ID?

纵饮孤独 提交于 2021-02-11 17:02:00
问题 My class is like below: [Table("tblUser")] public class User { [Key] public int Id { get; set; } public string Title { get; set; } } Using Dapper.Contrib, is there a way to get the User record by Title instead of Id? If I query like below, it works. But, I want to filter on Title column which is not a key. await connection.GetAsync<User>(Id); 回答1: Looking at the documentation, Dapper.Contrib does not support retrieval of records using criteria other than key. In other words, it does not

Dapper.Contrib: How to get a row by filtering on column other than ID?

房东的猫 提交于 2021-02-11 17:00:48
问题 My class is like below: [Table("tblUser")] public class User { [Key] public int Id { get; set; } public string Title { get; set; } } Using Dapper.Contrib, is there a way to get the User record by Title instead of Id? If I query like below, it works. But, I want to filter on Title column which is not a key. await connection.GetAsync<User>(Id); 回答1: Looking at the documentation, Dapper.Contrib does not support retrieval of records using criteria other than key. In other words, it does not

dapper “IN” clause not working with multiple values

坚强是说给别人听的谎言 提交于 2021-02-08 13:51:56
问题 Scenario: I have a string property in my model that holds the IDs from a MultiSelectList @Html.ListBox . If I select two list items, my property value will look like this 0100,0500 . The problem: Dapper where clause will only work with a single value: CODE IN (@SomeCode) // for example, 0100 or 0500 returns results CODE IN (@SomeCode) // 0100,0500 does not return results. 回答1: That's because you don't need to tell Dapper to use parenthesis () . It will do fine by its own. Try this: var codes

How do I get an IDbTransaction from an IDbContext?

允我心安 提交于 2021-02-08 13:16:41
问题 An IDbContext has a DatabaseFacade , which has a CurrentTransaction property. But the CurrentTransaction is an IDbContextTransaction . I want to pass an IDbTransaction to Dapper. How do I get an IDbTransaction instead of an IDbContextTransaction ? 回答1: Currently (up to latest at this time EF Core 2.0) there is no official way to do that. But you can use the following custom extension method to get it from IDbContextTransaction : using Microsoft.EntityFrameworkCore.Infrastructure; using

在.NetCore(C#)中使用ODP.NET Core+Dapper操作Oracle数据库

試著忘記壹切 提交于 2021-02-08 11:55:03
前言 Oracle 关系数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的 适应高吞吐量的数据库解决方案。 现在的系统主要的技术栈是Java / .Net Core,Java方面不必说对Oracle支持肯定没问题,.Net Core很少会使用到 Oracle数据库。 目前我现开发的项目是.Net Core与 Oracle 数据库, 所以我想到用.Net Core来写个Oracle数据库访问层,可以方便的使用Oracle的数据和存储过程。 ODP.NET Core是一个ADO.NET驱动程序,提供从Microsoft .NET Core客户端到Oracle数据库的快速数据访问。它可以在Windows和Linux上运行。ODP.NET由一个100%托管代码动态链接库Oracle.ManagedDataAccess.dll组成,可通过NuGet安装获得。 这个 Oracle.ManagedDataAccess.Core 是真的方便,不用安装Oracle客户端,兼容性、便捷性,开箱即用。 简单使用 首先用nuget安装这个 Oracle.ManagedDataAccess.Core ,之后就可以执各类操作了,不过从代码量上看还是比较繁琐的,上代码: var connStr = $"DATA

How to use Dapper to automatically map remaining columns to dictionary?

馋奶兔 提交于 2021-02-08 10:30:51
问题 I am attempting to use Dapper to map to my DTO: public class MyDto { public int Id { get; set; } public string Code { get; set; } public IDictionary<string, object> AdditionalColumns { get; set; } } I can have an instance of MyDto populate the first two properties based on convention, but I'm not sure how to tell Dapper to map all remaining columns into the dictionary. connection.Query<MyDto>("Get_Something", commandType: CommandType.StoredProcedure, param: parameters); The stored procedure

MySQL + Dapper Extensions: Error in SQL syntax

走远了吗. 提交于 2021-02-08 05:46:18
问题 I am trying to do CRUD operations using Dapper Extensions. But I am getting error while inserting data to MySQL database as follows: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near [......] at line [....] If I use MSSQL database, Dapper Extensions is working correctly. Why I am getting this error with MySQL? 回答1: The error is because Dapper Extensions is generating the query for SQL server (by default