dapper

Getting Dapper to return an empty string instead of a null string

扶醉桌前 提交于 2019-12-04 03:22:52
问题 I know it's kind of the wrong thing to do, but I'm dealing with a legacy codebase that has NULLS when it means empty strings and vice versa. I can't immediately see how it is possible, but is it possible to get (or modifiy dapper so it will) return an empty string instead of a null string when mapping back from the database. 回答1: Dapper doesn't call any setter when it sees a null , so options might include: set the default value to "" in the constructor check for null in the accessor So:

What .Net orms or MicroOrms support async operations and PostgreSql

别说谁变了你拦得住时间么 提交于 2019-12-04 03:19:01
问题 What ORM's support async operations and postgresql ? I prefer simple MicroOrms like Dapper and OrmLite because they seems to have great performance and they are really simple, but they do not support async operations as far as I can tell. Maybe I am wrong, but isn't important to make all IO bound operations async to get the full benefits of say an async web service that needs to scale? So what are the options regarding an MicroOrm with support for both async operations and Postgresql? I have

How to use Dapper in ServiceStack

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:07:28
Currently, I am using OrmLite for DB operations. I am also planning to use Dapper ORM, but can anyone point me how to integrate DapperORM in ServiceStack. Do I need to implement both IDbConnection and IDbConnectionFactory interfaces with Dapper and plugin into the container. public override void Configure(Container container) { container.Register<IDbConnectionFactory>( c => new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["default"].ConnectionString, SqlServerDialect.Provider)); container.Register<IDbConnection>(c => c.Resolve<IDbConnectionFactory>().OpenDbConnection())

Dynamic where clause in dapper

时光毁灭记忆、已成空白 提交于 2019-12-04 03:03:07
Is it possible to add and remove criteria on the fly with dapper? I need this to implement user driven filtering. It is not feasible to have a query for each filter as there are too many combinations. At the most basic level, you can just build the TSQL dynamically in a StringBuilder - adding extra and c.Name = @name etc . Don't worry about extra parameters; send them all - the library inspects the command and doesn't add any parameters that obviously aren't used. There is a second, newer API for this specific scenario, but I can't remember the specifics without checking (and I'm not at a

Can I return a collection of multiple Derived Types from Dapper query

僤鯓⒐⒋嵵緔 提交于 2019-12-04 00:23:47
I have a class structure similar to this: public abstract class Device { public int DeviceId { get; set; } //Additional Properties } public class DeviceA : Device { //Specific Behaviour } public class DeviceB : Device { //Specific Behaviour } I need to retrieve a list of Devices, or a single Device which is instantiated as the appropriate derived type (based upon a Type value in the Device Record in the DB). That is, the collection of Device objects should contain a number of objects with different Types, all of which are derived from Device . I have implemented this the following way, but

Dapper Multi Mapping with QueryMultiple

末鹿安然 提交于 2019-12-04 00:02:57
I have a stored procedure that returns multiple result sets. I'm executing this with dapper. One of the result sets is Person JOIN Checks, where Person can have many Checks. The end goal is to have distinct person objects that have a collection of check objects. QueryMutliple gives me a Sqlmapper.GridReader . I see an overload of SqlMapper.GridReader.Read() that takes a Func<TFirst, TSecond, TReturn> . Is there an example of how to use this? Ronnie Overby Here's how I got it working: var q = _sqlConnection.QueryMultiple("MySproc", myParams, commandType: CommandType.StoredProcedure); var set1 =

is there an ExecuteScalar in Dapper

我的梦境 提交于 2019-12-03 22:13:34
it looks like there was an ExecuteScalar in Dapper... http://code.google.com/p/dapper-dot-net/issues/attachmentText?id=22&aid=220000000&name=ExecuteScalar.cs&token=9e2fd8899022f507b140ffb883c60e34 Was ExecuteScalar renamed or removed? Can this now be achieved with .Query or .Query<T>? ExecuteScalar was just added in 1.28: https://www.nuget.org/packages/Dapper I was able to call ExecuteScalar< T > with version 1.42.0 public Boolean BeforeToday(DateTime dateInQuestion) { try { using (var conn = new SqlConnection(ConnectionString)) { String sql = @"SELECT CONVERT(bit, CASE WHEN getdate() >

“MultiLevels” Mapping Dapper using SplitOn

情到浓时终转凉″ 提交于 2019-12-03 21:28:13
Most of examples/question just introduce solutions to map "only one" level of the query using split on like this: var sql = "SELECT P.Id, P.FirstName, P.LastName, " + "A.Id AS AddressId, A.StreetNumber, A.StreetName, A.City, A.State " + "FROM People P INNER JOIN Addresses A ON A.AddressId = P.AddressId; "; db.Query<Person, Address, Person>( sql, (person, address) => { person.Address = address; return person; }, splitOn: "AddressId" ).ToList(); I have a query like this one (just an example): Select * from Country C inner join State S on C.CountryId = S.CountryId inner join City Ct on S.StateId

Return Values from Dapper.net query with stored procedure

為{幸葍}努か 提交于 2019-12-03 20:48:51
问题 I am trying to call a stored procedure using Dapper.Net and get return values. p.Add("@INCIDENT_ID", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); var retResults = con.Execute("usp_GetIncidentID", p, commandType:CommandType.StoredProcedure); int IncidentID = p.Get<int>("INCIDENT_ID"); I have tried a couple of different things with the parameter direction and using the "@INCIDENT_ID" . If you step through the results, you can see that the proper return values are coming

Need Help in applying SOLID principles

谁都会走 提交于 2019-12-03 16:30:17
Really impressed with Juile Lerman's pluralsight course on "EF in Enterprise" and decided to build my demo app. I am using VS 2012 and latest versions of EF,SQL Server and MVC. I am building a demo application which applies SOLID principles. I am doing this to better understand how to implement DI & unit testing. I have used DB first approach for this demo application. It contains only one table named UserDetails and below is how it looks in SQL server. I will use this table for CRUD operations. Below is how i have layered my application : 1. WESModel Solution: This layer contains my Model1