oceanicwang / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Should be possible to use struct types as parameters #127

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Given this:

const string taskDescSql =
@"SELECT [DESC] AS [Desc] FROM [SHIFTCODES] WHERE [Code] = @Code AND [PROGRAM] 
= @Program";

struct TaskKey
{
  public string Code { get; set; }
  public string Program { get; set; }
}

static string GetTaskDescription(DbConnection conn, TaskKey key, DbTransaction 
tx)
{
  var result = conn.Query<string>(taskDescSql, key, tx);
  return result.FirstOrDefault();
}

this produces an InvalidProgramException.

However, if I use an anonymous type (which should be unnecessary), it works:

static string GetTaskDescription(DbConnection conn, TaskKey key, DbTransaction 
tx)
{
  var result = conn.Query<string>(taskDescSql, new { Code = key.Code, Program = key.Program }, tx);
  return result.FirstOrDefault();
}

What version of the product are you using? On what operating system?
.NET 4.5, Windows 8

Original issue reported on code.google.com by karl.wac...@gmail.com on 12 Dec 2012 at 12:17

GoogleCodeExporter commented 8 years ago
Interesting question; I haven't added anything for struct parameters, but I 
can't see any reason *not* to, other than the very minor of boxing. I can't 
think of a good reason this shouldn't work (other than: that code doesn't 
exist), and we support structs in the output. I can add to the list

Original comment by marc.gravell on 12 Dec 2012 at 7:23