tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Insufficient parameters supplied to the command

todor-dk opened this issue · comments

Using the latest NuGet package 1.7.0, simple Update operations fail with the error: Insufficient parameters supplied to the command. This happens if there is a Guid property present on the entity. The same works in version 1.6.3.

Code to reproduce:

// Add reference to NuGet: System.Data.SQLite
// Add reference to NuGet: Dapper.Extensions

using Dapper;
using DapperExtensions;
using System.Data.SQLite;

public static void Main()
{
	string tempDb = Path.Combine(Path.GetTempPath(), $"DB_{Guid.NewGuid()}.sqlite");

	SQLiteConnection connection = new SQLiteConnection();
	connection.ParseViaFramework = true;
	connection.ConnectionString = $"data source=\"{tempDb}\";failifmissing=False;foreign keys=False;binaryguid=True";

	connection.Open();
	using (SQLiteCommand command = connection.CreateCommand())
	{
		command.CommandText = "CREATE TABLE [Entities] ([Id] guid PRIMARY KEY NOT NULL, [Name] text);";
		command.ExecuteNonQuery();
		command.CommandText = "INSERT INTO [Entities] ([Id], [Name]) VALUES ('02D16168-1E2E-4D5B-97E1-6CFCA3EF4B87', 'John');";
		command.ExecuteNonQuery();
	}

	DapperExtensions.DapperExtensions.SqlDialect = new DapperExtensions.Sql.SqliteDialect();
	DapperExtensions.DapperExtensions.DefaultMapper = typeof(DapperExtensions.Mapper.PluralizedAutoClassMapper<>);

	string sql = "SELECT * FROM [Entities]";
	Entity entity = connection.Query<Entity>(sql).ToArray().First();
	System.Diagnostics.Debug.Assert(entity.Name == "John");

	entity.Name = "Doe";
	connection.Update<Entity>(entity);  // <--- Fails Here !!!!

	connection.Close();
	File.Delete(tempDb);
}

private class Entity
{
	[System.ComponentModel.DataAnnotations.Key]
	public Guid Id { get; set; }

	public string Name { get; set; }
}