dapper-contrib

Dapper.Contrib: How to get a row by filtering on column other than ID?

纵饮孤独 提交于 2021-02-11 17:02:00
问题 My class is like below: [Table("tblUser")] public class User { [Key] public int Id { get; set; } public string Title { get; set; } } Using Dapper.Contrib, is there a way to get the User record by Title instead of Id? If I query like below, it works. But, I want to filter on Title column which is not a key. await connection.GetAsync<User>(Id); 回答1: Looking at the documentation, Dapper.Contrib does not support retrieval of records using criteria other than key. In other words, it does not

Dapper.Contrib: How to get a row by filtering on column other than ID?

房东的猫 提交于 2021-02-11 17:00:48
问题 My class is like below: [Table("tblUser")] public class User { [Key] public int Id { get; set; } public string Title { get; set; } } Using Dapper.Contrib, is there a way to get the User record by Title instead of Id? If I query like below, it works. But, I want to filter on Title column which is not a key. await connection.GetAsync<User>(Id); 回答1: Looking at the documentation, Dapper.Contrib does not support retrieval of records using criteria other than key. In other words, it does not

How to Get entity by Unique Key using Dapper.Contrib?

有些话、适合烂在心里 提交于 2021-01-28 23:59:13
问题 I have an object, assume public class User { [Key] int TheId { get; set; } string Name { get; set; } int Age { get; set; } } TheId is my auto increment column and Name is my unique key. When saving a user, I want to check its existence by: var user= connection.Get<User>("John"); But, because of my Key is not Name but TheId , I can't do this. If I set Name property as [KeyExplicit] that time when I want to save my user by: connection.Insert(myUser); This time, dapper expect TheId property

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

邮差的信 提交于 2020-04-17 08:42:24
问题 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 (nvarchar(80),null) So I need to map MyClass.LastName to MyClasses.Last-Name and have a hell of a time... When I write a custom Insert query it all works, but I would like to use the .Insert statement of one of the Dapper extensions packages. I tried Dapper.Contrib, but this

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

馋奶兔 提交于 2020-04-17 08:39:06
问题 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 (nvarchar(80),null) So I need to map MyClass.LastName to MyClasses.Last-Name and have a hell of a time... When I write a custom Insert query it all works, but I would like to use the .Insert statement of one of the Dapper extensions packages. I tried Dapper.Contrib, but this

How to properly “Singularize” table names with Dapper.Contrib?

你。 提交于 2020-04-13 14:53:58
问题 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 Dapper.Contrib library. But when I run Insert function Dapper pluralize table names in generated SQL queries. SQL table "Student": CREATE TABLE Student StudentId int NOT NULL PRIMARY KEY, FirstName varchar(50), LastName varchar(50) C# code public class Student

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

瘦欲@ 提交于 2020-01-05 08:31:57
问题 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 Code { get; set; } public InvoiceKind Kind { get; set; } [Write(false)] [Computed] public string FakeProperty { get; set; } } using (var connection = My.ConnectionFactory()) { connection.Open(); var invoices = connection.GetAll<InvoiceContrib>().ToList(); //

Dapper.Contrib Insert Exception

≯℡__Kan透↙ 提交于 2019-12-24 18:40:42
问题 On asp.net core application when i execute insert operating application throws error. previously application was asp.net core 1.1 recently i updated to asp.net core 2.0 using (var con = _connectionFactory.CreateConnection()) { con.Open(); using (var transaction = con.BeginTransaction()) { try { if (regions.Any()) { con.Insert(regions.Select(c => { c.UserId = userId; return c; }), transaction); } transaction.Commit(); } catch(Exception exception) { transaction.Rollback(); } } } exception was

Use Dapper.Contrib with inheritance

假如想象 提交于 2019-12-13 03:13:34
问题 When trying to use Contrib's CRUD methods in an object where the properties are in an inherited object I get an Entity must have at least one [Key] or [ExplicitKey] property error. Here is a simplified version of my objects: public class BaseObject { public string Delete() { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString)) { db.Delete(this); } } } and this public class Product: BaseObject { [Key] public int id { get; set; } public