micro-orm

Mapping char(8) to string property with Dapper

▼魔方 西西 提交于 2019-12-06 23:36:40
问题 I have the following table, abridged: CREATE TABLE [dbo].[TERMINAL] ( [TERM_CODEID] SMALLINT NOT NULL, [TERM_ACTIVE] SMALLINT NOT NULL, [TERM_NAME] VARCHAR (30) NOT NULL, [TERM_SLA] CHAR (8) NOT NULL, [TERM_SERIAL] VARCHAR (8) NULL, [TERM_VERSION] VARCHAR (8) NULL, [TERM_STATUS] INT NULL, ) When I try the following Dapper code - and I'm a complete Dapper novice, found it yesterday - I get an error: using (var conn = new SqlConnection("data source=ourServer; initial catalog=ourDb;user id=sa

Query spatial data with dapper

让人想犯罪 __ 提交于 2019-12-05 16:38:25
I've found some related questions , but the author gave up and went ahead with using stored procedures to do the 'mapping'. This is actually a continuation question from here Model public class Store { public int Id { get; private set; } public string Name { get; set; } public string Address { get; set; } public DbGeography Location { get; set; } } Querying using (SqlConnection conn = SqlHelper.GetOpenConnection()) { const string sql = "Select * from Stores"; return conn.Query<Store>(sql, new { Tenant_Id = tenantId }); } Dapper doesn't understand spatial data, and as many had said, it wasn't

Mapping char(8) to string property with Dapper

限于喜欢 提交于 2019-12-05 02:45:36
I have the following table, abridged: CREATE TABLE [dbo].[TERMINAL] ( [TERM_CODEID] SMALLINT NOT NULL, [TERM_ACTIVE] SMALLINT NOT NULL, [TERM_NAME] VARCHAR (30) NOT NULL, [TERM_SLA] CHAR (8) NOT NULL, [TERM_SERIAL] VARCHAR (8) NULL, [TERM_VERSION] VARCHAR (8) NULL, [TERM_STATUS] INT NULL, ) When I try the following Dapper code - and I'm a complete Dapper novice, found it yesterday - I get an error: using (var conn = new SqlConnection("data source=ourServer; initial catalog=ourDb;user id=sa;password=ourPassword;")) { conn.Open(); var terms = conn.Query<Terminal>("select * from TERMINAL"); } The

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

Why does Azure Database perform better with transactions

南楼画角 提交于 2019-12-04 03:43:40
We decided to use a micro-orm against an Azure Database. As our business only needs "inserts" and "selects", we decided to suppress all code-managed SqlTransaction (no concurrency issues on data). Then, we noticed that our instance of Azure Database responded very slowly. The " rpc completed " event occured in delays that are hundreds times the time needed to run a simple sql statement. Next, we benchmarked our code with EF6 and we saw that the server responded very quickly. As EF6 implements a built-in transaction, we decided to restore the SqlTransaction (ReadCommited) on the micro-orm and

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

Dapper with Access, update statement partially not working

吃可爱长大的小学妹 提交于 2019-12-01 14:57:35
I have a product class and tried to evaluate Dapper with Access database.. Select, Delete and Insert operations are working fine, but I have a problem with update operation. It is working in one way only code below) When I tried to change the Description based on ProductNumber it works (updateStatement2) and Description get updated, but when I tried to change the ProductNumber based on Description (updateStatement1) it doesn't work and ProductNumber doesn't get updated. It bit strange to me. Is it a bug or am I missing anything?. My database is just a basic one and no primary keys set. I have

Dapper with Access, update statement partially not working

与世无争的帅哥 提交于 2019-12-01 12:36:15
问题 I have a product class and tried to evaluate Dapper with Access database.. Select, Delete and Insert operations are working fine, but I have a problem with update operation. It is working in one way only code below) When I tried to change the Description based on ProductNumber it works (updateStatement2) and Description get updated, but when I tried to change the ProductNumber based on Description (updateStatement1) it doesn't work and ProductNumber doesn't get updated. It bit strange to me.

How to generate model from database using Dapper?

人走茶凉 提交于 2019-11-28 17:19:38
I am coming from PetaPoco camp. PetaPoco has a T4 template which generates model from the database. Is anything similar available for Dapper? I installed Dapper using NuGet and added SqlHelper.cs, but I didn't find anything which generates model from the database. Void Ray Dapper itself provides few extension methods (Query, Execute) for the connection object and does not have "model generator." Perhaps some other framework can be used to generate POCO's based on the db schema. Update: Database tables to C# POCO classes T4 template <#@ template language="C#" debug="True" #> <#@ assembly name=

How to generate model from database using Dapper?

穿精又带淫゛_ 提交于 2019-11-27 10:36:47
问题 I am coming from PetaPoco camp. PetaPoco has a T4 template which generates model from the database. Is anything similar available for Dapper? I installed Dapper using NuGet and added SqlHelper.cs, but I didn't find anything which generates model from the database. 回答1: Dapper itself provides few extension methods (Query, Execute) for the connection object and does not have "model generator." Perhaps some other framework can be used to generate POCO's based on the db schema. Update: Database