dapper

Dapper.SimpleCRUD Insert / Update / Get fails with message “Entity must have at least one [Key] property”

假装没事ソ 提交于 2019-12-10 13:33:40
问题 I'm a new baby in Dapper. Trying to incorporate CRUD operations with Dapper and Dapper.SimpleCRUD lib. Here is the sample code... My Data Model Looks like Class Product { public string prodId {get;set;} public string prodName {get;set;} public string Location {get;set;} } Dapper Implementation - Insert public void Insert(Product item) { using(var con = GetConnection()) { con.Insert(item); } } Since the ProdId in the Db is an Identity Column it fails. How does it indicate ProdId is an Identity

Using dapper, why is a temp table created in one use of a connection not available in a second use of the same connection

怎甘沉沦 提交于 2019-12-10 12:45:56
问题 I'm trying to perform a series of SQL*Server steps using dapper from C#. One step creates a temp table and populates it. Following steps query data from the temp table. The create/populate seems to run successfully, but the first query from the temp table fails saying: "Invalid object name '#GetPageOfGlobalUsers'." using (SqlConnection connection = DBConnectionProvider.CreateConnection()) { ... misc setup stuff... connection.Execute(@" create table #GetPageOfGlobalUsers(row int, EmailAddress

Multi-Mapper in Dapper one to many relations

青春壹個敷衍的年華 提交于 2019-12-10 11:51:03
问题 I am trying to get the value of my database with a relation one to many i have my object like this Student [Table("Student")] public class Student : IStudent { public int Id { get; set; } public string Lastname { get; set; } public string FirstMidName { get; set; } public DateTime? EnrollmentDate { get; set; } [Write(false)] public IEnumerable<Enrollment> Enrollments { get; set; } } Enrollment [Table("Enrollment")] public class Enrollment { public int Id { get; set; } public int CourseId {

Many to Many in Linq using Dapper

 ̄綄美尐妖づ 提交于 2019-12-10 10:37:04
问题 I have Places, each place can have many tags. Each tag can be assigned to many places. public class Place { public int Id { get; set; } public string PlaceName { get; set; } public IEnumerable<Tag> Tags { get; set; } } public class Tag { public int Id { get; set; } public string TagName { get; set; } } public class TagPlace { public int Id { get; set; } public PlaceId { get; set; } public TagId { get; set; } } The database has equivalent tables with foreign keys as appropriate. I want to get

Passing DTO to my ViewModels constructor to map properties

☆樱花仙子☆ 提交于 2019-12-10 09:29:12
问题 In my solution I have two projects. Project 1 (Core) Mapping SQL to DTO using Dapper Project 2 (WebUI - ASP.NET MVC 4) Here I use a ViewModel per View. Examples of a Controller [HttpGet] public ActionResult Edit(int id) { // Get my ProductDto in Core var product = Using<ProductService>().Single(id); var vm = new ProductFormModel(product); return View(vm); } Examples of a ViewModel public class ProductFormModel : BaseViewModel, ICreateProductCommand { public int ProductId { get; set; } public

Query spatial data with dapper

丶灬走出姿态 提交于 2019-12-10 06:58:04
问题 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

Dapper parameterised queries with LINQ autogenerated types

☆樱花仙子☆ 提交于 2019-12-10 04:26:53
问题 I'm using a combination of LINQ and Dapper in my work. I'm replacing my LINQ code with Dapper in places for performance reasons. I have a lot of LINQ data objects created by dragging and dropping into the Visual Studio database diagram from SQL Server. In the following instance I already have a LINQ object in memory and I'd like to pass it to Dapper as the parameters for a query. For example: Animal animal = con.Query<Animal>(" select * " + " from animal " + " where animalid = @AnimalId " + "

Is there a way of using MultiMapping and QueryMultiple together in Dapper?

无人久伴 提交于 2019-12-10 03:05:42
问题 I have a few queries that I need to run together and I can do so using the QueryMultiple feature. But in this case I've not been able to find out how could I use MultiMapping . Does anyone know a way of achieving this? 回答1: I think this is what you're looking for though it's hard to tell without an example of the query you are trying to execute. var sql = @"Select * From Parent Left Join Child on Child.ParentID = Parent.ParentID Where Parent.ParentID = @id ... more queries"; using(var reader

Using Dapper-dot-net, how do I map SQL uniqueidentifier column to a .Net type?

六眼飞鱼酱① 提交于 2019-12-10 01:42:58
问题 I have an existing database that uses the SQL "uniqueidentifier" type, which looks like a different GUID format than a .Net GUID. Question: Using Dapper, how do I map SQL uniqueidentifier column to .Net? Issue: Using Dapper-dot-net, when I map the column using the .Net GUID type, it compiles and runs, but all of the .ToString() output displays the same incorrect GUID. (well it doesn't match what I see in SSMS) When I try to map the column using the string type, I get a compiler error. Ideas?

Invalid cast when returning mysql LAST_INSERT_ID() using dapper.net

假如想象 提交于 2019-12-10 01:04:59
问题 This question has been covered for MSSQL here: How do I perform an insert and return inserted identity with Dapper? but this solution does not work with mysql. To cast the LAST_INSERT_ID() to integer with mysql you have to do this: SELECT CAST(LAST_INSERT_ID() AS UNSIGNED INTEGER); The stack trace is: Dapper.<QueryInternal>d__13`1.MoveNext() in sqlMapper.cs:607 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +159 System.Linq.Enumerable.ToList(IEnumerable`1 source) +36 Dapper