Commit ae71b7be authored by Sam's avatar Sam

Merge pull request #60 from bundy845/master

Allows a class to have a reserved word as a column name.
parents 8b405c70 7fd9b973
...@@ -32,6 +32,7 @@ private static void Setup() ...@@ -32,6 +32,7 @@ private static void Setup()
connection.Open(); 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 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 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"); Console.WriteLine("Created database");
} }
......
...@@ -33,6 +33,14 @@ public class Car ...@@ -33,6 +33,14 @@ public class Car
public string Name { get; set; } 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 public class Tests
{ {
private IDbConnection GetOpenConnection() private IDbConnection GetOpenConnection()
...@@ -75,7 +83,7 @@ public void InsertGetUpdate() ...@@ -75,7 +83,7 @@ public void InsertGetUpdate()
{ {
using (var connection = GetOpenConnection()) using (var connection = GetOpenConnection())
{ {
connection.Get<IUser>(3).IsNull(); connection.Get<User>(3).IsNull();
var id = connection.Insert(new User {Name = "Adam", Age = 10}); var id = connection.Insert(new User {Name = "Adam", Age = 10});
...@@ -161,5 +169,17 @@ public void BuilderTemplateWOComposition() ...@@ -161,5 +169,17 @@ public void BuilderTemplateWOComposition()
throw new Exception("Query failed"); 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) ...@@ -180,7 +180,7 @@ private static string GetTableName(Type type)
for (var i = 0; i < allPropertiesExceptKey.Count(); i++) for (var i = 0; i < allPropertiesExceptKey.Count(); i++)
{ {
var property = allPropertiesExceptKey.ElementAt(i); var property = allPropertiesExceptKey.ElementAt(i);
sbColumnList.Append(property.Name); sbColumnList.AppendFormat("[{0}]", property.Name);
if (i < allPropertiesExceptKey.Count() - 1) if (i < allPropertiesExceptKey.Count() - 1)
sbColumnList.Append(", "); sbColumnList.Append(", ");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment