dapper

Questions about Dapper SQL queries and parameters with PostgreSQL

天涯浪子 提交于 2020-01-02 08:34:42
问题 I´m currently learning about Dapper. I have searched a lot here and other places (including this) and I could not find concrete answers to my doubts: ¿Does Dapper use a generic SQL dialect or it's specific for DB engine? I mean, it uses the SQL syntax expected in the underlaying database engine? At first and after reading over a dozen of examples I thought that the SQL queries where generic, but now trying on PostgresSQL ODBC I have encountered problems with syntax and parameters. Using this

asp.net mvc core how can I return a Json query

笑着哭i 提交于 2020-01-02 05:53:57
问题 First and foremost I Know how to return a Json Query by doing this public JsonResult streams() { using (var conn = new NpgsqlConnection(Connectionstring)) { conn.Open(); var credentials = conn.Query<Streams>("select id,name from streams").ToList(); ViewData["Message"] = "Your application description page."; conn.Close(); return Json(credentials); } } That code above returns Json for me from the database, however now I am actually returning the Json from the SQL code by changing the query to

asp.net mvc core how can I return a Json query

给你一囗甜甜゛ 提交于 2020-01-02 05:53:21
问题 First and foremost I Know how to return a Json Query by doing this public JsonResult streams() { using (var conn = new NpgsqlConnection(Connectionstring)) { conn.Open(); var credentials = conn.Query<Streams>("select id,name from streams").ToList(); ViewData["Message"] = "Your application description page."; conn.Close(); return Json(credentials); } } That code above returns Json for me from the database, however now I am actually returning the Json from the SQL code by changing the query to

How to get values for child objects using Dapper ORM?

南笙酒味 提交于 2020-01-02 04:50:50
问题 I am retrieving profile details with the following: var profiles = connection.Query<Models.PROFILE>( "SELECT * FROM PROFILES WHERE ID=@ID", new { ID = profileID }); // IEnumerable var profile = profiles.First<Models.PROFILE>(); The profile object contains other collections like profileImages. The problem is that the item count for every child object is zero. Also I only want to get data for say, profileImages. Is there something that needs to be set to query the child objects, and if so, is

Dapper & Oracle Clob type

余生颓废 提交于 2020-01-02 02:55:31
问题 I am using dapper to do some oracle access. I have a scenario where I have to have an output parameter with a type of OracleDbType.Clob. As I am using dapper and thus using the base DbType enumeration I am using the DbType.Object enum as suggested here http://docs.oracle.com/html/B14164_01/featOraCommand.htm to stand in for OracleDbType.Clob. However, this sets the command parameter (deep down in dapper) to be of DbType object and oracle type Blob (as the DbConnection providers a concrete

Can a Dapper DynamicParameters object be enumerated like a dictionary of parameters?

浪尽此生 提交于 2020-01-02 01:13:10
问题 I know I can use a ParameterDirection with Dapper.DynamicParameters: var parameters = new DynamicParameters(); parameters.Add("iparam", 42); parameters.Add("oparam", null, DbType.Int32, ParameterDirection.Output); connection.Execute(sql, parameters); But can I do so when using a Dictionary<string, object> ? var parameters = new Dictionary<string, object>(); parameters.Add("iparam", 42); parameters.Add("oparam", /* ??? */ ); connection.Execute(sql, parameters); Alternatively, how may I iterate

DAL with dapper and C#

江枫思渺然 提交于 2020-01-01 06:56:07
问题 I have a data access layer that utilises Dapper but can't help feeling that it could be far more elegant. The DAL is just passing in parameters and mapping the model as per the named responses of the model so that part is straight forward at least, but I hate code that looks duplicated. Here is an example public IEnumerable<Product> ProductSearch(int? userId, DateTime? modifiedAfter, DateTime? modifiedBefore, Guid? productId) { IList<Product> products; using (var connection = _connection

CancellationToken with async Dapper methods?

为君一笑 提交于 2019-12-31 17:51:13
问题 I'm using Dapper 1.31 from Nuget. I have this very simple code snippet, string connString = ""; string query = ""; int val = 0; CancellationTokenSource tokenSource = new CancellationTokenSource(); using (IDbConnection conn = new SqlConnection(connString)) { conn.Open(); val = (await conn.QueryAsync<int>(query, tokenSource.Token)).FirstOrDefault(); } When I press F12 on QueryAsync , it points me to public static Task<IEnumerable<T>> QueryAsync<T> ( this IDbConnection cnn, string sql, dynamic

Using Dapper, how do I pass in the values for a sql type as param?

∥☆過路亽.° 提交于 2019-12-31 05:34:07
问题 I'm attempting to use dapper and pass into a stored procedure a list of integers which I have defined here using DDL CREATE TYPE [dbo].[BrandIDSet] AS TABLE ([BrandID] INT NULL); I've created this stored procedure: CREATE PROCEDURE dbo.usp_getFilteredCatalogItems @BrandIDSet [dbo].[BrandIDSet] READONLY and attempting to pass in in c# code the value for that parameter as public async Task<PaginatedCatalogItemsVM> GetFilteredCatalogItems(int pageSize, int pageNumber, List<int> brandIDSet) { ..

Why is Dapper unable to return multiple inserted row ids?

筅森魡賤 提交于 2019-12-31 01:28:05
问题 I have a SQL Server table into which rows are inserted using: var sql = @" DECLARE @InsertedRows AS TABLE (Id BIGINT); INSERT INTO Person ([Name], [Age]) OUTPUT Inserted.Id INTO @InsertedRows VALUES (@Name, @Age); SELECT Id FROM @InsertedRows;"; Person person = ...; var id = connection.Query<long>(sql, person).First(); This all works well however if I try to insert multiple items and return all the inserted ids using: IEnumerable<Person> people = ...; var ids = connection.Query<long>(sql,