dapper

How do I pass JSON as a primitive PostgreSQL type to a function using Dapper?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 14:32:50
问题 I have a PostgreSQL function that takes in a parameter of type json . Using Dapper, how do I execute a call that passes the object to the PostgreSQL function such that PostgreSQL recognizes the type as json instead of as text ? Example PostgreSQL Function that takes in json type CREATE OR REPLACE FUNCTION testfuncthattakesinjson(heroes json) RETURNS SETOF characters LANGUAGE 'sql' STABLE ROWS 100 AS $BODY$ SELECT c.* FROM characters c JOIN json_array_elements(heroes) j ON c.first_name = j->>

Dapper or MySql not finding stored procedures that contain a full stop “.”

情到浓时终转凉″ 提交于 2019-12-12 12:48:52
问题 I've got a simple c# console that uses the Dapper ORM to make a call to a local MySql database in order to execute a stored procedure called users.UserCreate . However, when running the query I get an exception saying Procedure or function 'UserCreate' cannot be found in database 'users' But users isn't the database local_db is. Here an example use: public virtual Task CreateAsync(User user) { using (var con = new MySqlConnection(_dbConn)) return con.ExecuteAsync("users.UserCreate", user,

Dapper getting “Specified cast is not valid.” for ReturnValue parameter value

谁说胖子不能爱 提交于 2019-12-12 10:59:22
问题 I am trying to use SCOPE_IDENTITY to return a long primary key back to c# using the ReturnValue option for DynamicParameter. Here is sample code from the Dapper website: var p = new DynamicParameters(); p.Add("@a", 11); p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output); p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); cnn.Execute("spMagicProc", p, commandType: commandType.StoredProcedure); int b = p.Get<int>("@b"); int c = p.Get<int>("@c");

RuntimeBinderInternalCompilerException when using Microsoft.SqlServer.Types with Dapper

一个人想着一个人 提交于 2019-12-12 10:46:28
问题 Using a Sql Server Data Tools project whose target platform is set to one of: SQL Server 2008 SQL Server 2012 SQL Server 2014 And deploying to (localdb)\Projects or (localdb)\ProjectsV12 Calling a stored procedure that returns a Geometry, Geography or HierachyId type such as: CREATE PROCEDURE [dbo].[SelectSqlGeometry] @x Geometry AS SELECT @x as y RETURN 0 The following calling code: var result = Connection.Query("dbo.SelectSqlGeometry", new { x = geometry }, commandType: CommandType

Insert a list using dapper.NET C#

冷暖自知 提交于 2019-12-12 10:41:54
问题 I'd like to insert a list of objects in an SQL table. I know this question here but I don't understand. Here is my class : public class MyObject { public int? ID { get; set; } public string ObjectType { get; set; } public string Content { get; set; } public string PreviewContent { get; set; } public static void SaveList(List<MyObject> lst) { using (DBConnection connection = new DBConnection()) { if (connection.Connection.State != ConnectionState.Open) connection.Connection.Open(); connection

return a list of data via stored proc to dapper

北战南征 提交于 2019-12-12 09:59:54
问题 I am trying to return data using Dapper via stored proc My DTO Class is similar to below (removed some properties for brevity) public class CarDTO { public int CarID { get; set; } public string Manufacturer { get; set; } public List<CarOptionDTO> CarOptions { get; set; } } So basically in the DB I have a CarOption table that has a CarID column - i.e a Car can have many options. My DAL Layer call at the minute is as below: private string getCarDataSp = "[dbo].[GetCarData]"; public IEnumerable

Dapper - Bulk insert of new items and get back new IDs

这一生的挚爱 提交于 2019-12-12 09:57:18
问题 I am using dapper to add multiple new students in one db hit using this method: db.ExecuteAsync(@"INSERT Student(Name,Age) values (@Name,@Age)", students.Select(s => new { Name = s.Name, Age = s.Age }) ); But the problem I don't have the new ids. Can I make one db hit and still some how get the new ids ? And if not, what is the most efficient way of performing such bulk insert ? 回答1: That is not a bulk insert; it is basically just shorthand that unrolls the loop; although interestingly

Clarification of Dapper Example Code

三世轮回 提交于 2019-12-12 09:34:10
问题 I'm trying to grok Dapper and seem to be missing something very fundamental, can someone explain the following code taken from the Dapper home page on Google code and explain why there is no From clause, and the second param to the Query method (dynamic) is passed an anonymous type, I gather this is somehow setting up a command object, but would like an explanation in mere mortal terminology. Thank you, Stephen public class Dog { public int? Age { get; set; } public Guid Id { get; set; }

Dapper. Paging

浪子不回头ぞ 提交于 2019-12-12 07:08:13
问题 I am trying Dapper ORM and I am querying a a Posts table. But I would like to get paged results ... 1 - How can I do this? Isn't there a helper for this? 2 - Can Dapper Query return an IQueryable? Thank You, Miguel 回答1: 1) Dapper doesn't have a built-in pagination feature. But its not too hard to implement it directly in the query. Example: SELECT * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY InsertDate) AS RowNum, * FROM Posts WHERE InsertDate >= '1900-01-01' ) AS result WHERE RowNum >= 1 //

How to use Dapper.FluentMap.Dommel.Mapping for multiple Ids

早过忘川 提交于 2019-12-12 05:18:13
问题 I'm having a problem using Dapper.FluentMap.Dommel.Mapping . When I log the mapping, the system identifies that a property with the name ID already exists and throws the exception. But mapped Id belongs to another object. How can I solve this problem? BaseEntity.cs public abstract class BaseEntity { public virtual long Id { get; set; } } Sistema.cs public class Sistema : BaseEntity { public override long Id { get; set; } public string Nome { get; set; } } Arquivo.cs public class Arquivo :