Commit 73d0ba34 authored by tms's avatar tms

Updated Table methods to better support multi-DB

No sense in escaping TableName only for update, "from" isn't universally
optional for deletes, First() should be virtual to allow alternatives to
TOP 1
parent 8b405c70
...@@ -73,7 +73,7 @@ public int Update(TId id, dynamic data) ...@@ -73,7 +73,7 @@ public int Update(TId id, dynamic data)
List<string> paramNames = GetParamNames((object)data); List<string> paramNames = GetParamNames((object)data);
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.Append("update [").Append(TableName).Append("] set "); builder.Append("update ").Append(TableName).Append(" set ");
builder.AppendLine(string.Join(",", paramNames.Where(n => n != "Id").Select(p => p + "= @" + p))); builder.AppendLine(string.Join(",", paramNames.Where(n => n != "Id").Select(p => p + "= @" + p)));
builder.Append("where Id = @Id"); builder.Append("where Id = @Id");
...@@ -90,7 +90,7 @@ public int Update(TId id, dynamic data) ...@@ -90,7 +90,7 @@ public int Update(TId id, dynamic data)
/// <returns></returns> /// <returns></returns>
public bool Delete(TId id) public bool Delete(TId id)
{ {
return database.Execute("delete " + TableName + " where Id = @id", new { id }) > 0; return database.Execute("delete from " + TableName + " where Id = @id", new { id }) > 0;
} }
/// <summary> /// <summary>
...@@ -103,7 +103,7 @@ public T Get(TId id) ...@@ -103,7 +103,7 @@ public T Get(TId id)
return database.Query<T>("select * from " + TableName + " where Id = @id", new { id }).FirstOrDefault(); return database.Query<T>("select * from " + TableName + " where Id = @id", new { id }).FirstOrDefault();
} }
public T First() public virtual T First()
{ {
return database.Query<T>("select top 1 * from " + TableName).FirstOrDefault(); return database.Query<T>("select top 1 * from " + TableName).FirstOrDefault();
} }
......
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