Commit 29171eaa authored by Sam's avatar Sam

Merge pull request #26 from greygeek/master

Added test for insert updating object's key
parents 726af71d eed8b6f5
......@@ -104,6 +104,17 @@ public void InsertGetUpdate()
}
}
public void InsertCheckKey()
{
using (var connection = GetOpenConnection())
{
connection.Get<IUser>(3).IsNull();
User user = new User { Name = "Adamb", Age = 10 };
int id = (int)connection.Insert(user);
user.Id.IsEqualTo(id);
}
}
public void BuilderSelectClause()
{
using (var connection = GetOpenConnection())
......
......@@ -486,14 +486,9 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
var r = connection.Query("select @@IDENTITY id", transaction: transaction, commandTimeout: commandTimeout);
int id = 0;
foreach (var p in keyProperties)
{
var value = ((IDictionary<string, object>)r.First())[p.Name.ToLower()];
p.SetValue(entityToInsert, value, null);
if (id == 0)
id = Convert.ToInt32(value);
}
int id = (int)r.First().id;
if (keyProperties.Any())
keyProperties.First().SetValue(entityToInsert, id, null);
return id;
}
}
......
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