dapper

Querying into a complex object with Dapper

大兔子大兔子 提交于 2019-12-08 17:20:53
问题 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 =

C#, Dapper, SQL Server and Connection Pooling

喜你入骨 提交于 2019-12-08 16:38:54
问题 I've written some code to write some data to SQL Server, using Dapper. I don't need to wait for this write to complete before continuing other work, so want to use Task.Run() to make this asynchronous. I have (using) statements for calling this in the rest of my system: using (IDataAccess ida = new DAL()) { ida.WriteMessageToDB(id, routingKey, msgBody); } My DAL will automatically check the dbConnection.State when the using statement is ran, and attempt a simple fix if it's closed. This works

Referenced assembly Dapper does not have a strong name

江枫思渺然 提交于 2019-12-08 16:37:22
问题 I installed dapper from NuGet. When I try to compile the code I'm getting the error Referenced assembly Dapper does not have a strong name What causes this? 回答1: You see the error because the package you use doesn't have a strong name, that is it doesn't use signing. Signing ensures the authenticity of an assembly. See Anything wrong with NOT signing a .NET assembly? for more information about the reasons assemblies should (or should not) be signed. If an assembly is not signed, it cannot be

Traditional sql approach VS ORM [closed]

醉酒当歌 提交于 2019-12-08 16:11:31
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 4 years ago . I am really frustrated of searching this answer that what is better - Traditional System.Data.SqlClient approach or using any ORM like EF or Dapper I have seen many comparisons through many links, some are : https://github.com/StackExchange/dapper-dot-net http://www.dontpaniclabs.com/blog/post/2014/05/01/speed-comparison-dapper-vs-entity-framework/ ORM vs traditional

How to read an SQL query generated by Dapper?

﹥>﹥吖頭↗ 提交于 2019-12-08 15:13:33
问题 I have a standard code: public IEnumerable ExperimentSelect(object parameters) { using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); var dynamicparam = new DynamicParameters(parameters); var rows = connection.Query("[dbo].[ptbSapOrderSelect]", dynamicparam, commandType: CommandType.StoredProcedure); if (rows.Any()) TotalRows = ((long)rows.ToList()[0].TotalRows); return rows; } } How to automate saving queries generated by Dapper to the file using eg NLog? I am

Cannot select some rows with npgsql on a “Portuguese” database

丶灬走出姿态 提交于 2019-12-08 05:15:53
问题 I have a postgresql database that was created with "SQL_ASCII" and template "template0". It holds data in Portuguese so I have data such as "Não", "Feijão", "Avô". When I try to retrieve rows that have these kind of characters "~^" it does not work, otherwise it works. Errors: "Error parsing column 6 (sempresa=0 - String)"} Message = "Can not convert byte [C3] in index 0 of the code page specified for Unicode." I'm using Npgsql and Dapper <packages> <package id="Dapper" version="1.50.2"

Get table name from TableAttribute Dapper.Contrib

倖福魔咒の 提交于 2019-12-08 05:12:55
问题 I'm using Dapper and Dapper.Contrib to map objects from database. I have a class name where I define table name for this class because it is different from the actual class name. Class: [Table("tblUser")] public class User { public int Id { get; set; } public string Title { get; set; } } How can I get the table name which is set Table data annotation attribute? EDIT: I've used following to get it working var tAttribute = (TableAttribute)typeof(T).GetCustomAttributes(typeof(TableAttribute),

How to use SQL Bulk Copy with Dapper .Net ?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 04:51:00
问题 I am working with Dapper .net for Bulk insert operation in SQL Tables. I am thinking to user SQKBulk copy with Dapper .Net but don't have any experience How to use SqlbulkCopy with Dapper .Net your help is Highly appreciated 回答1: It is not good idea to use dapper for bulk insert, because there it will not fast. The better case for this is use of SqlBulkCopy class. But if you want use Dapper for bulk insert, you can find solution here. 来源: https://stackoverflow.com/questions/29070108/how-to

Multi mapping query with Dapper

泪湿孤枕 提交于 2019-12-08 04:18:19
问题 I have these classes and their equivalent tables in my database: public class Entity { public int Id { get; set; } public List<EntityIdentifier> Identifiers { get; set; } public BaseEntity() { Identifiers = new List<EntityIdentifier>(); } } public class EntityIdentifier { public int Id { get; set; } public int EntityId { get; set; } public string Code { get; set; } public string Value { get; set; } } I want to query the database with Dapper and automap the data. I have this example of multi

Select All Posts With All Their Tags

僤鯓⒐⒋嵵緔 提交于 2019-12-08 02:48:11
问题 There are many questions about this, but not enough definitive answers, especially using SQL Server which I am in this case. I have 3 tables to represent blog posts and tags associated with it. I want to run a query that will get all the posts and each posts tags with it - I need both the tag id and name. The result needs to be easily serializable into my C# classes. I am also trying to use Dapper.net but that is not the most important part. Obviously many websites do this, I want to know the