dapper

Using decimal with specific precision as output parameters with Dapper

依然范特西╮ 提交于 2019-12-01 20:43:26
问题 I am evaluating Dapper as a replacement for custom and cumbersome code and so far all was very good and promising. But this morning I have stumbled on a problem with Dynamic parameters and cannot find a solution. A stored procedure calculates the Account Balance and the Available Balance for a customer returning its result in two decimal output parameters. These decimals are declared in the stored procedure with Precision=18 and Scale=2. This procedure works perfectly with the current

Using decimal with specific precision as output parameters with Dapper

落花浮王杯 提交于 2019-12-01 20:08:11
I am evaluating Dapper as a replacement for custom and cumbersome code and so far all was very good and promising. But this morning I have stumbled on a problem with Dynamic parameters and cannot find a solution. A stored procedure calculates the Account Balance and the Available Balance for a customer returning its result in two decimal output parameters. These decimals are declared in the stored procedure with Precision=18 and Scale=2. This procedure works perfectly with the current standard methods. But in Dapper I cannot find a way to pass these parameters and specify the scale so all I

Comparing QUERY and EXECUTE in Dapper

一笑奈何 提交于 2019-12-01 17:41:09
I would like to ask if what is the best to use when INSERTING, UPDATING, DELETING, REMOVING, QUERY SPECIFIC DATA using DAPPER? I'm really confused in using EXECUTE and QUERY command in DAPPER.. This should not be confusing at all, especially if you look at the signature of the methods exposed by the Dapper (as per documentation): public static IEnumerable<T> Query<T>(this IDbConnection cnn, string sql, object param = null, SqlTransaction transaction = null, bool buffered = true) Query method is specifically meant for executing a select statement internally, which can return the IEnumerable of

Getting Dapper to return an empty string instead of a null string

為{幸葍}努か 提交于 2019-12-01 17:40:48
I know it's kind of the wrong thing to do, but I'm dealing with a legacy codebase that has NULLS when it means empty strings and vice versa. I can't immediately see how it is possible, but is it possible to get (or modifiy dapper so it will) return an empty string instead of a null string when mapping back from the database. Dapper doesn't call any setter when it sees a null , so options might include: set the default value to "" in the constructor check for null in the accessor So: public class SomeDto { public SomeDto() { Name = ""; } public string Name {get;set;} } or: public class SomeDto

Dapper Many-to-Many Query

家住魔仙堡 提交于 2019-12-01 17:02:27
问题 I am trying to write a query to get a user in the system with all of his/her roles. There is a many-to-many relationship between users and roles. The joiner table is SystemUserUserRole with columns UserId and RoleId . My models are below: SystemUser Model [Key] public int UserId { get; set; } [Required] [MaxLength(75)] public string FirstName { get; set; } [Required] [MaxLength(75)] public string LastName { get; set; } [Required] [MaxLength(15)] public string Phone { get; set; } [Required]

Querying into a complex object with Dapper

江枫思渺然 提交于 2019-12-01 16:50:28
I have a Customer class with the following properties: public int Id { get; set; } public string Name { get; set; } public int AddressId { get; set; } public Address Address { get; set; } My goal is to write a Dapper query that will use an Inner Join to populate the entire Address property within each Customer that is returned. Here is what I have and it is working but I am wondering if this is the cleanest/simplest way to do it: StringBuilder sql = new StringBuilder(); using (var conn = GetOpenConnection()) { sql.AppendLine("SELECT c.Id, c.Name, c.AddressId, a.Address1, a.Address2, a.City, a

What .Net orms or MicroOrms support async operations and PostgreSql

风流意气都作罢 提交于 2019-12-01 16:42:16
What ORM's support async operations and postgresql ? I prefer simple MicroOrms like Dapper and OrmLite because they seems to have great performance and they are really simple, but they do not support async operations as far as I can tell. Maybe I am wrong, but isn't important to make all IO bound operations async to get the full benefits of say an async web service that needs to scale? So what are the options regarding an MicroOrm with support for both async operations and Postgresql? I have just read about a new Orm called Insight.Data, but I am unsure whether it properly supports PostgreSql.

Dapper 入门

≯℡__Kan透↙ 提交于 2019-12-01 16:23:46
中文文档连接: https://www.w3cschool.cn/dapperorm/dapperorm-toj931f2.html 官网文档连接: https://dapper-tutorial.net/dapper 小程序连接: https://pan.baidu.com/s/1qqfDXKOCjjsw9gTjzoWWdw 提取码:lxui 什么是Dapper Dapper 是一个简单的.NET对象映射器,在速度方面具有"King of Micro ORM"的头衔,几乎与使用原始的ADO.NET数据读取器一样快。ORM是一个对象关系映射器,它负责数据库和编程语言之间的映射。 Dapper通过扩展IDbConnection提供一些有用的扩展方法去查询您的数据库。 Dapper是如何工作的 它可以分为三个步骤: 创建一个IDbConnection接口对象; 编写一个查询SQL来执行CRUD操作; 将查询SQL作为Execute方法的参数传递。 方法   Dapper会用以下几个方法扩展您的IDbConnection接口: Execute Query QueryFirst QueryFirstOrDefault QuerySingle QuerySingleOrDefault QueryMultiple 参数 执行和查询方法可以用以下几种不同的方式使用参数: 匿名类型 动态类型

Dapper ambiguous extension methods

…衆ロ難τιáo~ 提交于 2019-12-01 16:01:57
I am testing Dapper as a ORM solution and ran into a problem with some extension methods like Execute or QueryMultiple : using (SQLiteConnection con = new SQLiteConnection(GetConnectionString())) { con.Open(); string sql = @" select * from Customer where Id = @id; select * from Address where CustomerId = @id;"; // QueryMultiple extension ambiguous? using (var multi = con.QueryMultiple(sql, new { id = 1 })) { Customer customer = multi.Read<Customer>().Single(); Address address = multi.Read<Address>().Single(); } con.Close(); } I get the error The call is ambiguous between the following methods

Net笔记-EF/Dapper/ORM

烈酒焚心 提交于 2019-12-01 15:31:53
个人备查笔记 Q:EF DateTime 默认值多数据兼容问题: mysql:NOW()或sysdate() Sql Server: GetDate() EF兼容使用 ANSI SQL: builder.Property(x => x.UpdatedOn).HasDefaultValueSql("CURRENT_TIMESTAMP"); Q:EF/Linq语句转Raw SQL: 代码转载备查 转载 来源: https://stackoverflow.com/questions/37527783/get-sql-code-from-an-entity-framework-core-iqueryablet EF Core 2.x: public static class QueryableExtensions { private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo(); private static readonly FieldInfo QueryCompilerField = typeof(EntityQueryProvider).GetTypeInfo().DeclaredFields.First(x => x.Name == "