dapper

Dapper: is it possible to customize the type mapping of a specific field of a specific type?

浪子不回头ぞ 提交于 2019-12-04 12:17:01
Let's say I have this User class: public class User { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public DateTime DateCreated { get; set; } public DateTime LastLogin { get; set; } } Which I want to map to the following table: CREATE TABLE "user" ( "ID" int(11) NOT NULL AUTO_INCREMENT, "FirstName" varchar(45) DEFAULT NULL, "LastName" varchar(45) DEFAULT NULL, "Email" varchar(255) NOT NULL, "DateCreated" int(11) NOT NULL, "LastLogin" int(11) NOT NULL, PRIMARY KEY ("ID") ) Or put in simpler words: I want

Dapper type mapping hangs in Windows 10 for large queries

两盒软妹~` 提交于 2019-12-04 12:12:18
I have a very simply query in my projects that returns ~1.3 million rows: var aliases = ctx.Query<sec_entity_alias>(@"select * from sec_entity_alias"); The class that is mapped to is: public partial class sec_entity_alias { public int id { get; set; } public int sec_entity_id { get; set; } public byte sec_entity_alias_type_id { get; set; } public string symbol { get; set; } public virtual sec_entity_alias_type sec_entity_alias_type { get; set; } } When I run the query it hangs indefinitely and pegs the CPU. When I remove the dapper type mapping and instead run the following, the query returns

[LINQ2Dapper]最完整Dapper To Linq框架(六)---多表联合与匿名类型返回

牧云@^-^@ 提交于 2019-12-04 11:39:23
目录 [LINQ2Dapper]最完整Dapper To Linq框架(一)---基础查询 [LINQ2Dapper]最完整Dapper To Linq框架(二)---动态化查询 [LINQ2Dapper]最完整Dapper To Linq框架(三)---实体类关系映射 [LINQ2Dapper]最完整Dapper To Linq框架(四)---Linq和SQL并行使用 [LINQ2Dapper]最完整Dapper To Linq框架(五)---查看Linq实际执行的SQL [LINQ2Dapper]最完整Dapper To Linq框架(六)---多表联合与匿名类型返回 1.多表联合查询 默认情况下Where,Get,ToList,PageList等函数只支持单表操作, 如 var comment = conn.QuerySet<Comment>() .Where(x => x.Id.NotIn(new int[] { 1, 2, 3 }) && x.SubTime.AddMinutes(50) < DateTime.Now.AddDays(-1) && x.Type.IsNotNull()) .ToList();  3.1.2后支持双表和三表同时映射操作,需要通过From函数指定映射表, 如 var comment = conn.QuerySet<Comment>()

Dapper的扩展这个你知道嘛?

纵饮孤独 提交于 2019-12-04 10:33:43
原文: Dapper的扩展这个你知道嘛? 之前写的 ORM对比文章 中,我选Dapper作为底层ADO的基础访问框架后,我对此再次进行进一步的深入研究,发现里面还有延伸了一些好用的扩展方法和特性,那我便简单的跟大家说一下特性标签。 一、TableAttribute 特性   这个先对简单,就是对模型进行定义表名,如果你未标注表名特性,默认去模型类型名称,并且此特性只能标注在类上,不能标注在属性,方法等其它作用体上; 二、KeyAttribute [隐式]主键特性   为什么我把它定义隐式呢,关键在于在Insert时,如果你用它标记了一个属性,那这个属性的值无法对应插入到数据表里,比较适合自增类型主键和数据库默认有赋值的主键字段   代码模拟:   [Table("Person")] public class Person { [Key] public Guid ID { get; set; } public string Name { get; set; }     public byte Age { get; set; } }  //最终的脚本是:INSERT INTO [Person] (Name,Age) VALUES (@Name,@Age) 三、ExplicitKeyAttribute [显式]主键特性   我之前也比较纳闷怎么需要定义两种KEY特性,在尝试DEMO后

Dapper with Attributes mapping

China☆狼群 提交于 2019-12-04 07:40:50
问题 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 =

Dapper and Oracle CRUD issues, how to?

孤街浪徒 提交于 2019-12-04 04:41:46
How do i make Dapper.NET to CRUD my Oracle DB? I have table named: PLAYER_LOG it's identity is done by trigger, here is the sql SELECT SQ_MASTER_SEQUENCE.NEXTVAL INTO tmpVar FROM dual; :NEW.ID := tmpVar; my Model is: public class PlayerLogStorage : IEntity //-> here is the identity { public string Cli { get; set; } public string PlayerAnswer { get; set; } public DateTime InsertDate { get; set; } } here is my insert: using (IDbConnection ctx = DbConnectionProvider.Instance.Connection) { ctx.Query<PlayerLogStorage>("INSERT INTO PLAYER_LOG (CLI, ANSWER, INSERT_DATE) VALUES (:Cli, :PlayerAnswer,

How Dapper chooses between 2 columns with the same name

夙愿已清 提交于 2019-12-04 04:37:19
问题 I have some inherited code that uses Dapper to map a SQL SELECT into an object. The SELECT has multiple columns with the same name (some columns are omitted for brevity). SELECT created_timestamp AS CreatedDate, imported_timestamp AS CreatedDate FROM Orders WHERE OrderId = @OrderId An analysis of the data shows only one of the 2 CreatedDate columns are populated for each record. Running some tests revealed that Dapper seems to be picking the non-NULL CreatedDate. I couldn't find any

How do I use Dapper to get the return value of stored proc?

心已入冬 提交于 2019-12-04 04:06:39
I'm using Dapper in asp.net mvc 4 project .net f/w 4.6.1 using sql server 2016 express <packages> <package id="Dapper" version="1.50.2" targetFramework="net461" /> </packages> I have a stored proc which deletes from 2 tables which should be transactional ALTER PROCEDURE [dbo].[FeedbackDelete] @FeedbackID UNIQUEIDENTIFIER AS SET NOCOUNT OFF SET XACT_ABORT ON BEGIN TRANSACTION DELETE FROM dbo.Document WHERE FeedbackId = @FeedbackID IF(@@ERROR != 0) BEGIN ROLLBACK TRANSACTION RETURN 1 END DELETE FROM [dbo].[Feedback] WHERE [FeedbackID] = @FeedbackID IF(@@ERROR != 0 OR @@ROWCOUNT != 1) BEGIN

Dapper sqlmapperextensions automatically adds “s” to tablename?

Deadly 提交于 2019-12-04 03:54:56
This is my first experience with Dapper.Contrib (latest version from Nuget) and it's a strange situation: using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); var product = cn.Get<Product>(1); } On SqlMapperExtensions, it raises the error Invalid object name 'Products' : public static T Get<T>(this IDbConnection connection, dynamic id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class { var type = typeof(T); string sql; if (!GetQueries.TryGetValue(type.TypeHandle, out sql)) } The database receives the command select * from Products where Id =

Report Viewer X Dapper

核能气质少年 提交于 2019-12-04 03:43:39
问题 I'm feeding a ReportDataSource with a query using Dapper. However, I have an empty report, even with an IEnumerable loaded data. When you spend a Datatable works. How do I pass data from a query using Dapper for ReportViewer ? this.reportViewer.LocalReport.DataSources.Clear(); DataTable dt = new DataTable(); dt = CN.Query(Sql, param); Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(dt.TableName, dt); this.reportViewer.LocalReport