Permalink
Browse files

Fixed problems with Update using objects without keys and schema-qual…

…ified tables in InMemoryAdapter
  • Loading branch information...
1 parent 0e40b48 commit e61bd7ca7b87ec2c5f92a5aaadbcd636fc4db866 @markrendle committed Jan 25, 2013
@@ -7,6 +7,8 @@
namespace Simple.Data.Ado
{
+ using Extensions;
+
[Export("Ado", typeof (Adapter))]
public partial class AdoAdapter : Adapter, ICloneable
{
@@ -81,8 +83,10 @@ public ISchemaProvider SchemaProvider
public override IDictionary<string, object> GetKey(string tableName, IDictionary<string, object> record)
{
var homogenizedRecord = new Dictionary<string, object>(record, HomogenizedEqualityComparer.DefaultInstance);
- return GetKeyNames(tableName).ToDictionary(key => key,
- key => homogenizedRecord.ContainsKey(key) ? homogenizedRecord[key] : null);
+ return GetKeyNames(tableName)
+ .Select(k => k.Homogenize())
+ .Where(homogenizedRecord.ContainsKey)
+ .ToDictionary(key => key, key => homogenizedRecord[key]);
}
#region ICloneable Members
@@ -82,9 +82,17 @@ public AdoAdapterUpserter(AdoAdapter adapter, IDbTransaction transaction)
IDictionary<string, object> result;
try
{
- var criteria = ExpressionHelper.CriteriaDictionaryToExpression(tableName,
- _adapter.GetKey(tableName, row));
- result = Upsert(tableName, row, criteria, isResultRequired);
+ var key = _adapter.GetKey(tableName, row);
+ if (key.Count == 0)
+ {
+ result = new AdoAdapterInserter(_adapter).Insert(tableName, row, isResultRequired);
+ }
+ else
+ {
+ var criteria = ExpressionHelper.CriteriaDictionaryToExpression(tableName,
+ key);
+ result = Upsert(tableName, row, criteria, isResultRequired);
+ }
}
catch (Exception ex)
{
Oops, something went wrong.

0 comments on commit e61bd7c

Please sign in to comment.