dapper

handler mapping of string to varchar in dapper

Deadly 提交于 2019-12-07 04:18:57
问题 i found these code in dapper: sealed partial class DbString : Dapper.SqlMapper.ICustomQueryParameter { ... public void AddParameter(IDbCommand command, string name) { ... var param = command.CreateParameter(); param.ParameterName = name; param.Value = (object)Value ?? DBNull.Value; if (Length == -1 && Value != null && Value.Length <= 4000) { param.Size = 4000; } else { param.Size = Length; } ... } } can you tell me why code here need to compare the lenght to 4000? thank you. 回答1: Query-plan

What exactly is the “information” that dapper caches?

左心房为你撑大大i 提交于 2019-12-07 02:32:33
问题 On Dapper's documentation found here it states: " Limitations and caveats Dapper caches information about every query it runs , this allow it to materialize objects quickly and process parameters quickly. The current implementation caches this information in a ConcurrentDictionary object." What exactly does this mean? Ex: Is it caching returned data, or the query itself, or bits of both? It also says that " this [cached] data is never flushed ". How does this effect the "cached information"

Dapper Dynamic Parameters with Table Valued Parameters

允我心安 提交于 2019-12-07 02:11:53
问题 I was trying to create a generic method, which can read the parameters name and value from a class at Runtime and create parameter collection for Dapper query execution. Realized that till the point all parameters are Input type it works well, but if I have to add an Output / ReturnValue type parameters, then I need to work with DynamicParameters , else I cannot fetch the value of Output / ReturnValue parameters SP has following parameters: PersonList - TableValued - Input TestOutput - Int -

How to use SQL Bulk Copy with Dapper .Net ?

风格不统一 提交于 2019-12-07 00:45:41
I am working with Dapper .net for Bulk insert operation in SQL Tables. I am thinking to user SQKBulk copy with Dapper .Net but don't have any experience How to use SqlbulkCopy with Dapper .Net your help is Highly appreciated Alex Erygin It is not good idea to use dapper for bulk insert, because there it will not fast. The better case for this is use of SqlBulkCopy class. But if you want use Dapper for bulk insert, you can find solution here . 来源: https://stackoverflow.com/questions/29070108/how-to-use-sql-bulk-copy-with-dapper-net

Mapping char(8) to string property with Dapper

▼魔方 西西 提交于 2019-12-06 23:36:40
问题 I have the following table, abridged: CREATE TABLE [dbo].[TERMINAL] ( [TERM_CODEID] SMALLINT NOT NULL, [TERM_ACTIVE] SMALLINT NOT NULL, [TERM_NAME] VARCHAR (30) NOT NULL, [TERM_SLA] CHAR (8) NOT NULL, [TERM_SERIAL] VARCHAR (8) NULL, [TERM_VERSION] VARCHAR (8) NULL, [TERM_STATUS] INT NULL, ) When I try the following Dapper code - and I'm a complete Dapper novice, found it yesterday - I get an error: using (var conn = new SqlConnection("data source=ourServer; initial catalog=ourDb;user id=sa

Multi mapping query with Dapper

孤街醉人 提交于 2019-12-06 21:46:33
I have these classes and their equivalent tables in my database: public class Entity { public int Id { get; set; } public List<EntityIdentifier> Identifiers { get; set; } public BaseEntity() { Identifiers = new List<EntityIdentifier>(); } } public class EntityIdentifier { public int Id { get; set; } public int EntityId { get; set; } public string Code { get; set; } public string Value { get; set; } } I want to query the database with Dapper and automap the data. I have this example of multi mapping, from the Dapper git page : var sql = @"select * from #Posts p left join #Users u on u.Id = p

Mapping SqlGeography with Dapper

眉间皱痕 提交于 2019-12-06 21:25:57
问题 I have entity "Point", that contains Id, Text and geography coordinates. CREATE TABLE [Point] ( [Id] INT IDENTITY CONSTRAINT [PK_Point_Id] PRIMARY KEY, [Coords] GEOGRAPHY NOT NULL, [Text] NVARCHAR(32) NOT NULL, [CreationDate] DATETIME NOT NULL, [IsDeleted] BIT NOT NULL DEFAULT(0) ) CREATE PROCEDURE [InsertPoint] @text NVARCHAR(MAX), @coords GEOGRAPHY AS BEGIN INSERT INTO [Point](Text, Coords, CreationDate) VALUES(@text, @coords, GETUTCDATE()) SELECT * FROM [Point] WHERE [Id] = SCOPE_IDENTITY(

Dapper throws “Invalid type owner for DynamicMethod.”

强颜欢笑 提交于 2019-12-06 19:19:28
问题 So I'm trying to use Dapper.net and I'm liking it. What I'm not liking is when I try to batch-insert entities and I get the following error thrown: Invalid type owner for DynamicMethod. at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility, Boolean transparentMethod, StackCrawlMark& stackMark) at System.Reflection.Emit.DynamicMethod..ctor

How can I send a string as NULL to SQLServer using Dapper?

前提是你 提交于 2019-12-06 18:24:49
问题 I've got a scenario where a string in C# can be null . I need it to be NULL on SQLServer. I'm sending it to SQLServer using Dapper with a query like: connection.Query<MyObject>("[dbo].[sp_MyStoredProcedure]"), new { StartDate: startDate }, commandType: CommandType.StoredProcedure); Where startDate is the string that can sometimes be equal to null . The stored procedure's parameter is @StartDate varchar(10) = NULL When it's is NULL it returns all records. I've confirmed this behavior works via

How can I get Dapper to map .net datetime to datetime2?

泄露秘密 提交于 2019-12-06 17:00:21
问题 Pretty simple, I'm converting our existing system from EF to Dapper. For various corporate reasons we can't really change the database, some of the tables have columns that are of type DateTime2. Dapper converts any .net DateTime to DbType.DateTime. Someone must have bumped against this before and found an easy solution ? 回答1: Dapper is litterally a single file that you include into your code base. Just edit the file: Replace (around line 300): typeMap[typeof(Guid)] = DbType.Guid; typeMap