dapper

Dapper simple mapping

浪子不回头ぞ 提交于 2019-11-30 21:28:40
Table: create table Documents (Id int, SomeText varchar(100), CustomerId int, CustomerName varchar(100) ) insert into Documents (Id, SomeText, CustomerId, CustomerName) select 1, '1', 1, 'Name1' union all select 2, '2', 2, 'Name2' Classes: public class Document { public int Id { get; set; } public string SomeText { get; set; } public Customer { get; set; } } public class Customer { public int Id { get; set; } public string Name { get; set; } } How can I get all Documents with their Customers with Dapper? This gives me all documents, but the customer is null (of course): connection.Query

How can I use Dapper's strongly-typed query parameters with Sybase ASE?

醉酒当歌 提交于 2019-11-30 21:13:05
Dapper can pass query parameters as anonymous objects, and supports any ADO.NET data provider. However, when running the following query against the Sybase 15 ADO.NET drivers: using (var connection = new AseConnection("...")) { connection.Open(); var results = connection.Query<Foo>( "dbo.sp_columns", new { table_name = "dbo.sysusers"}, commandType: CommandType.StoredProcedure); } ... the following error is thrown: Sybase.Data.AseClient.AseException: Procedure sp_columns expects parameter @table_name, which was not supplied. at Sybase.Data.AseClient.AseCommand.ᜁ(Int32 A_0) at Sybase.Data

Return Values from Dapper.net query with stored procedure

北城余情 提交于 2019-11-30 17:51:29
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 down in the retResults value, but I am not able to access the values the way it is described in the

Dapper parameters not working

ⅰ亾dé卋堺 提交于 2019-11-30 14:08:24
I'm trying to use the Dapper orm with the following simple query: var sqlString = new StringBuilder(); sqlString.Append("select a.acct AccountNumber,"); sqlString.Append(" b.first_name FirstName,"); sqlString.Append(" b.last_name LastName,"); sqlString.Append(" a.rr RrNumber,"); sqlString.Append(" c.addr1 AddressLine1,"); sqlString.Append(" c.addr2 AddressLine2,"); sqlString.Append(" c.addr3 AddressLine3,"); sqlString.Append(" c.addr4 AddressLine4,"); sqlString.Append(" c.addr5 AddressLine5,"); sqlString.Append(" c.addr6 AddressLine6,"); sqlString.Append(" c.addr7 AddressLine7,"); sqlString

Is there anyway to iterate through a Dapper DynamicParameters object?

吃可爱长大的小学妹 提交于 2019-11-30 13:11:24
I need to make a generic logger to record certain insert/update statements so that my testers can verify the data being inserted is correct. My first thought was that I would just use a function that accepted DynamicParameters and I would foreach through the DynamicParameters to generate a string to list the parameter's name and value and make them easier to read for the testers. Unfortunately, Dapper.DynamicParameters does not contain a public definition for "GetEnumerator" Here is basic example of what I was hoping to do: string myFormattedListofParameters = ""; foreach (var p in

How to map multiple records from a single SP with Dapper-dot-net

半腔热情 提交于 2019-11-30 12:45:14
I'd like to use Dapper in a situation where the execution of a single stored procedure will return 50 multiple separate selects, none of the individual result sets will be very wide, maybe 20 or 30 columns at most. The code below is from the Dapper Tests and I'm wondering if this example is a good prototype to use. Thank you, Stephen public void TestMultiMap() { var createSql = @" create table #Users (Id int, Name varchar(20)) create table #Posts (Id int, OwnerId int, Content varchar(20)) insert #Users values(99, 'Sam') insert #Users values(2, 'I am') insert #Posts values(1, 99, 'Sams Post1')

When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id“, ”splitOn

吃可爱长大的小学妹 提交于 2019-11-30 12:45:04
问题 I'm trying to use the Multi-mapping feature of dapper to return a list of Album and associated Artist and Genre. public class Artist { public virtual int ArtistId { get; set; } public virtual string Name { get; set; } } public class Genre { public virtual int GenreId { get; set; } public virtual string Name { get; set; } public virtual string Description { get; set; } } public class Album { public virtual int AlbumId { get; set; } public virtual int GenreId { get; set; } public virtual int

Dapper and varchars

痴心易碎 提交于 2019-11-30 12:39:33
I found the following comment on the Dapper .NET project home page . Dapper supports varchar params, if you are executing a where clause on a varchar column using a param be sure to pass it in this way: Query<Thing>("select * from Thing where Name = @Name", new {Name = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = true }); On Sql Server it is crucial to use the unicode when querying unicode and ansi when querying non unicode I'm evaluating Dapper for use with a legacy database (SQL Server 2008), with lots of stored procedures with varchar parameters, and I'm a

Execute stored procedure w/parameters in Dapper

一个人想着一个人 提交于 2019-11-30 11:22:47
I'm using Dapper (thanks Sam , great project.) a micro ORM with a DAL and by some reason I'm not able to execute stored procedures with input parameters. In a example service I've the following code: public void GetSomething(int somethingId) { IRepository<Something, SomethingEnum> repository = UnitOfWork.GetRepository<Something, SomethingEnum>(); var param = new DynamicParameters(); param.Add("@somethingId", dbType: DbType.Int32, value:somethingId, direction: ParameterDirection.Input); var result = repository.Exec<Something>(SomethingEnum.spMyStoredProcedure, param); ... } When the execution

Net Core Connection String Dapper visual studio 2017

浪尽此生 提交于 2019-11-30 09:39:29
I am trying to get a Connection String set up in my .Net Core application but i keep getting the error: System.NullReferenceException: 'Object reference not set to an instance of an object.' I have tried adding the following to appsettings.json : "ConnectionStrings": { "Analysis": "Server=DESKTOP-MYSERVER;Database=MYDATABASE;User Id=sa; Password=Password123;Provider=System.Data.SqlClient;Trusted_Connection=True;MultipleActiveResultSets=true;Pooling=false;" } I also tried using web.config like I used to before .Net Core: <connectionStrings> <add name="Analysis" providerName="System.Data