Merge pull request #60 from bundy845/master

Allows a class to have a reserved word as a column name.
This commit is contained in:
Sam
2012-11-15 17:45:32 -08:00
3 changed files with 23 additions and 2 deletions
+1
View File
@@ -32,6 +32,7 @@ namespace Dapper.Contrib.Tests
connection.Open();
connection.Execute(@" create table Users (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, Age int not null) ");
connection.Execute(@" create table Automobiles (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null) ");
connection.Execute(@" create table Results (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, [Order] int not null) ");
}
Console.WriteLine("Created database");
}
+21 -1
View File
@@ -33,6 +33,14 @@ namespace Dapper.Contrib.Tests
public string Name { get; set; }
}
[Table("Results")]
public class Result
{
public int Id { get; set; }
public string Name { get; set; }
public int Order { get; set; }
}
public class Tests
{
private IDbConnection GetOpenConnection()
@@ -75,7 +83,7 @@ namespace Dapper.Contrib.Tests
{
using (var connection = GetOpenConnection())
{
connection.Get<IUser>(3).IsNull();
connection.Get<User>(3).IsNull();
var id = connection.Insert(new User {Name = "Adam", Age = 10});
@@ -161,5 +169,17 @@ namespace Dapper.Contrib.Tests
throw new Exception("Query failed");
}
}
public void InsertFieldWithReservedName()
{
using (var conneciton = GetOpenConnection())
{
var id = conneciton.Insert(new Result() { Name = "Adam", Order = 1 });
var result = conneciton.Get<Result>(id);
result.Order.IsEqualTo(1);
}
}
}
}
+1 -1
View File
@@ -180,7 +180,7 @@ namespace Dapper.Contrib.Extensions
for (var i = 0; i < allPropertiesExceptKey.Count(); i++)
{
var property = allPropertiesExceptKey.ElementAt(i);
sbColumnList.Append(property.Name);
sbColumnList.AppendFormat("[{0}]", property.Name);
if (i < allPropertiesExceptKey.Count() - 1)
sbColumnList.Append(", ");
}