dapper

using parameters with Dapper

折月煮酒 提交于 2019-12-13 07:03:27
问题 I have read a number of posts about this topic but still can't quite get it to work with my code. Not sure if postgreSQL changes things... Here is what I have that is (probably obviosly) not working: string mySelectQuery = @"select distribution_stop_information.unique_id_no as stop_unique_id_no, distribution_line_items.unique_id_no as line_unique_id_no, stop_name, stop_address,route_code AS RouteCode, customer_reference, distribution_line_items.datetime_created, rma_number from distribution

Mapping multiple objects in dapper using Split-on and Query Multiple together

自闭症网瘾萝莉.ら 提交于 2019-12-13 03:47:14
问题 Consider Role-Employee-Address An employee can have only one role but can have many addresses. So using split on is not efficient as we may get the duplicates of roles and employee. We can use query multiple, but i feel if there is a way we can capture the role and employee together in one result and address in another, then that would be better. In that case, instead of returning role and employee separately, we can directly join both in a single query and split on some column while mapping.

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

Navigate properties when using Dapper Extensions

左心房为你撑大大i 提交于 2019-12-13 00:49:32
问题 Im using DapperExtensions library for simple CRUD operations. When I add a navigate property to my model, I get an error message that this column is not in the database. Can you in any way change this so that Dapper Extensions ignores this property? Example of my model public class Order : EntityBase { public int OrderId { get; set; } public int MarketId { get; set; } public int ModelId { get; set; } public int ContactId { get; set; } public string Project { get; set; } public decimal

Can dapper deserialize json stored as text?

不问归期 提交于 2019-12-13 00:16:06
问题 public class MyType { public int Id { get; set;} public int[] MyArray { get; set; } } var sql = "SELECT id, MyArrayAsJson as MyArray"; var x = await connection.QueryAsync<MyType>(sql); I have a string stored in the database which looks like json: [1,2,3,4,5] When I query the db with Dapper, I would like dapper to deserialize to an object, MyType. Dapper wants MyArrayAsJson to be a string because it is, but I want it to deserialize to an int array. Is this possible? 回答1: Dapper wants nothing

Dapper insert or Update?

天涯浪子 提交于 2019-12-12 21:04:47
问题 I haven't started using Dapper just yet but just stumbled across it today as I was researching about bulk insert/updates. Currently I'm using EF6 but I would like to look at using Dapper in the future of my bulk stuff. For this app there could be ~15k records but I have other apps that could be ~100k records. I'm trying to research a way that I could convert the following EF code into Dapper. All it does is reads in a record from a file, look to see if that employee exists in the DB, if so it

Get data using inner join from Dapper

妖精的绣舞 提交于 2019-12-12 20:03:32
问题 I am working on DB operations on one project and developing WinForms App C# and I am using Dapper to get data out of DB, I am stuck at situation where I need to retrieve data using inner join. Eg. I've two tables Authors and Book as Follow : public class Authors { public int AuthorId { get; set; } public string AuthorName { get; set; } } public class Book { public int BookId { get; set; } public string AuthorId { get; set; } public string Title { get; set; } public string Description { get;

Dapper unable to cast object of type 'Microsoft.SqlServer.Types.SqlGeography' to type 'System.Data.Entity.Spatial.DbGeography'

安稳与你 提交于 2019-12-12 18:39:21
问题 I have EF configured with a Location field on my User table: public DbGeography Location { get; set; } However when I query my User table with: user = connection.Query<User>("update [User] set LastOnline = @lastOnline output INSERTED.* where Username = @un", new { lastOnline = DateTime.UtcNow, un = username }).First(); I get the following error: Message=Error parsing column 122 (Location=POINT (-118.2436849 34.0522342) - Object) Source=Dapper StackTrace: at Dapper.SqlMapper.ThrowDataException

Fill list object using dapper c#

a 夏天 提交于 2019-12-12 15:53:16
问题 I have two table in my database like this: And i have this class: class Ean { public string Code{ get; set; } } class Article { public int Id { get; set; } public string Name { get; set; } public List<Ean> BarCode { get; set; } } List<Article> arts = new List<Article>(); I create a list of article , and with a query using dapper . I would like to fill this list with the name of the article but also with a list of related ean Article. I try to do this query: SELECT ART.ID AS ID, ART.NAME AS

Generate a SQL clause using a Linq-to-Sql Expression

醉酒当歌 提交于 2019-12-12 14:47:04
问题 I would like to create a repository model that could take an Expression and use Linq-To-Sql to generate the required SQL statement. For example, I have a function such as this: // Possible criteria Expression<Func<Purchase,bool>> criteria1 = p => p.Price > 1000; // Function that should take that criteria and convert to SQL statement static IEnumerable<Customer> GetCustomers (Expression<Func<Purchase,bool>> criteria) { // ... } Inside the function, I would like to convert criteria to a SQL