Questions tagged [dapper-contrib]

Dapper.Contrib contains a number of helper methods for inserting, getting, updating and deleting records.

Dapper.Contrib contains a number of helper methods for inserting, getting, updating and deleting records.

Source: https://github.com/StackExchange/dapper-dot-net/tree/master/Dapper.Contrib

47 questions
18
votes
1 answer

How do I insert data when the primary key column is not an identity column?

I'm trying to insert data using Dapper.Contrib, in a table where the primary key column is not an identity column. The database table is created with this script: begin transaction create table dbo.Foos ( Id int not null, …
user247702
  • 23,641
  • 15
  • 110
  • 157
13
votes
3 answers

Dapper UpdateAsync ignore column

I am trying to update with Dapper.Contrib this table: public class MyTable { public int ID { get; set; } public int SomeColumn1 { get; set; } public int SomeColumn2 { get; set; } public int CreateUserID { get; set; } public int…
Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116
11
votes
1 answer

Dapper.Contrib - "only supports an entity with a single [Key] or [ExplicitKey]"

I'm using Dapper and Dapper.Contrib in an MVC5 c# environment and sometimes (!) when I deploy the production site I get errors stating: GetAll only supports an entity with a single [Key] or [ExplicitKey] property at …
Mackan
  • 6,200
  • 2
  • 25
  • 45
5
votes
2 answers

How to properly "Singularize" table names with Dapper.Contrib?

I have a .Net Core 3.1 Console application. In SQL Server database I have tables with singular names, the same as my POCO classes, which is convenient for matching and maintaining. For Insert, Update and Delete operations I want to use…
Elshad Shabanov
  • 483
  • 10
  • 17
5
votes
1 answer

What's the difference between [Computed] and [Write(false)] attributes?

This resource explains how Computed excludes a property (in an update only?). Specifie the property should be excluded from update. [Table("Invoice")] public class InvoiceContrib { [Key] public int InvoiceID { get; set; } public string…
SpiritBob
  • 2,355
  • 3
  • 24
  • 62
5
votes
1 answer

Dapper.Contrib methods unavailable for IDbConnection object

I am trying to use Dapper.Contrib to extend the functionality of the IDbConnection interface with, amongst others, the .insert() method. To do so, I have followed the somewhat brief and scattered documentation here and here. In short, I have used…
Wouter
  • 1,829
  • 3
  • 28
  • 34
5
votes
3 answers

Inserting object that should be mapped into different DB table depending on scenario

I have an object with properties names that exactly name the field names inside the DB table but I'm not sure how to insert it. The only thing different is the DB table name. So it's an object with a name of different model/mapped table but I want…
Euridice01
  • 2,510
  • 11
  • 44
  • 76
4
votes
1 answer

Is there a way to map properties to column names using some .Insert extension method for Dapper?

I have the following challenge with this class: Public Class MyClass Property Id As Integer Property LastName as String End Class The corresponding data table in the database has as fields: Id (int, not null) Last-Name…
Dabblernl
  • 15,831
  • 18
  • 96
  • 148
4
votes
2 answers

Insert complex objects from C# into SQL Server without Entity Framework and data tables

How to insert complex objects from C# into SQL Server without using Entity Framework and data tables (I thought about Dapper.Contrib but it is only for entities). I'm using stored procedures and Dapper for now, but I can insert only one object and…
3
votes
1 answer

Dapper.Contrib - InsertAsync fails to insert an HIERARCHYID key

We have a table in our project with a primary key of HIERARCHYID type: CREATE TABLE [dbo].[OurTable] ( [Id] HIERARCHYID NOT NULL, ) and the corresponding class to use with Dapper…
Darth Veyda
  • 828
  • 2
  • 12
  • 23
3
votes
1 answer

Inserting and MultiMapping using Dapper.Contrib

What I am attempting to do, is to be able to use complex objects both for retrieval and for writing back to the database. For example, I have two classes [Table("Children")] public class Child { public int Id { get; set; } public int…
Bruce Burge
  • 144
  • 1
  • 15
2
votes
1 answer

Writing a generic InsertData method using Dapper.Contrib and InsertAsync

I am fairly new to C# and Dapper. I am trying to write a generic Insert Data method for my project. I come from a Delphi environment so I am still finding my way around C#. Dapper seems fairly straight forward to use but I am experiencing some…
2
votes
2 answers

Updating DateTime to database is throwing SqlTypeException - SqlDateTime overflow

Executing following line of code: conn.Update(CashInItem) throws an exception: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM (line 465 in Contrib var updated = connection.Execute(sb.ToString(),…
Moshe Yalovsky
  • 121
  • 1
  • 1
  • 8