提交 ae71b7be 编写于 作者: S Sam

Merge pull request #60 from bundy845/master

Allows a class to have a reserved word as a column name.
......@@ -32,6 +32,7 @@ private static void Setup()
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");
}
......
......@@ -33,6 +33,14 @@ public class Car
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 @@ public void InsertGetUpdate()
{
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 @@ public void BuilderTemplateWOComposition()
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);
}
}
}
}
......@@ -180,7 +180,7 @@ private static string GetTableName(Type type)
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(", ");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册