dapper

C# Dapper using JSON_VALUE for SQL Server 2016

空扰寡人 提交于 2019-12-19 03:24:10
问题 I want to query data from my table using JSON_VALUE : var str = "123"; var value = "Name" using(var conn = GetMyConnection()) { var result = conn.QueryFirstOrDefault<string>( @"SELECT [Id] FROM [dbo].[MyTable] WHERE JSON_VALUE([JsonColumn], @MyQuery) = @Str", new { MyQuery = $"$.{value}", Str = str } ); } I try this in SQL Server, it is working: SELECT [Id] FROM [dbo].[MyTable] WHERE JSON_VALUE([JsonColumn], '$.Name') = '123' How should I adjust my code? 回答1: I try this in SQL Server, it

Dapper simple mapping

早过忘川 提交于 2019-12-19 03:24:10
问题 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

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 03:23:04
问题 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

Dapper parameters not working

為{幸葍}努か 提交于 2019-12-18 16:50:11
问题 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,"

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

你说的曾经没有我的故事 提交于 2019-12-18 15:12:19
问题 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))

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

﹥>﹥吖頭↗ 提交于 2019-12-18 15:11:42
问题 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))

Can AnsiStrings be used by default with Dapper?

十年热恋 提交于 2019-12-18 13:09:30
问题 I'm using Dapper against a database where strings are stored primarily in VarChar columns. By default Dapper uses NVarChar parameters when generating queries and while I can wrap each and every string parameter I use with DbString it'd be great to use AnsiStrings by default and use DbString for the NVarChar case. I tried changing the type map in the Dapper source from DbType.String to DbType.AnsiString however that seems to cause an error in the IL generation for the parameters delegate

Using Dapper.TVP TableValueParameter with other parameters

。_饼干妹妹 提交于 2019-12-18 12:58:04
问题 I have a procedure that takes in a table-valued parameter, along with others: CREATE PROCEDURE [dbo].[Update_Records] @currentYear INT, @country INT, @records Record_Table_Type READONLY AS and am trying to call this with Dapper.TVP. Here is the code I have so far: var recordsParameter = new List<SqlDataRecord>(); // This metadata matches 'Record_Table_Type' in the Database var recordsMetaData = new[] { new SqlMetaData("OriginalValue", SqlDbType.Decimal, 19, 4), new SqlMetaData("NewValue",

Dapper Column number rather than column name?

对着背影说爱祢 提交于 2019-12-18 05:11:22
问题 I have a very similar question to Dapper-dot-net "no column name", but the answer there is not getting me where I need. I'm writing a web interface and using dapper to get data from Stored Procedures from my client's ERP system. The SP returns 4 columns of data without column names. That being said the SP's are locked and I can't change them. I've tried to work around this by using a temp table in my query as Sam suggested. var grid = QueryMultiple(@"set nocount on declare @t table(Id int,

Dapper Multi-mapping Issue

扶醉桌前 提交于 2019-12-18 04:38:22
问题 Keep running into "When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id" error for the below code-block: var accounts = DbConnection.Query<Account, Branch, Application, Account>( "select Accounts.*, SplitAccount = '', Branches.*, SplitBranch = '', Applications.*" + " from Accounts" + " join Branches" + " on Accounts.BranchId = Branches.BranchId" + " join Applications" + " on Accounts.ApplicationId = Applications.ApplicationId" + " where Accounts