Browse files

Optimized Update/Delete by entry key.

  • Loading branch information...
1 parent 27fed2e commit dd8b2fcc434e9b96b5468167be79938043bdd43b @object object committed Dec 18, 2012
View
10 Simple.Data.OData/ODataTableAdapter.cs
@@ -113,14 +113,20 @@ private int UpdateByExpression(string tableName, IDictionary<string, object> dat
{
var cmd = new CommandBuilder().BuildCommand(tableName, criteria);
var clientCommand = GetODataClientCommand(cmd);
- return GetODataClient(transaction).UpdateEntries(tableName, clientCommand.CommandText, data);
+ var client = GetODataClient(transaction);
+ return clientCommand.FilterIsKey ?
+ client.UpdateEntry(tableName, clientCommand.FilterAsKey, data) :
+ client.UpdateEntries(tableName, clientCommand.CommandText, data);
}
private int DeleteByExpression(string tableName, SimpleExpression criteria, IAdapterTransaction transaction)
{
var cmd = new CommandBuilder().BuildCommand(tableName, criteria);
var clientCommand = GetODataClientCommand(cmd);
- return GetODataClient(transaction).DeleteEntries(tableName, clientCommand.CommandText);
+ var client = GetODataClient(transaction);
+ return clientCommand.FilterIsKey ?
+ client.DeleteEntry(tableName, clientCommand.FilterAsKey) :
+ client.DeleteEntries(tableName, clientCommand.CommandText);
}
private ODataClient GetODataClient(IAdapterTransaction transaction = null)
View
2 Simple.OData.Client/ICommand.cs
@@ -23,5 +23,7 @@ public interface ICommand
IClientWithCommand NavigateTo(string linkName);
IClientWithCommand Function(string functionName);
IClientWithCommand Parameters(IDictionary<string, object> parameters);
+ bool FilterIsKey { get; }
+ IDictionary<string, object> FilterAsKey { get; }
}
}
View
10 Simple.OData.Client/ODataClientWithCommand.cs
@@ -204,5 +204,15 @@ public IClientWithCommand NavigateTo(string linkName)
{
return _command.NavigateTo(linkName);
}
+
+ public bool FilterIsKey
+ {
+ get { return _command.FilterIsKey; }
+ }
+
+ public IDictionary<string, object> FilterAsKey
+ {
+ get { return _command.FilterAsKey; }
+ }
}
}
View
16 Simple.OData.Client/ODataCommand.cs
@@ -178,6 +178,22 @@ public IClientWithCommand NavigateTo(string linkName)
return _client.Link(this, linkName);
}
+ public bool FilterIsKey
+ {
+ get
+ {
+ return _namedKeyValues != null;
+ }
+ }
+
+ public IDictionary<string, object> FilterAsKey
+ {
+ get
+ {
+ return _namedKeyValues;
+ }
+ }
+
public ODataCommand WithInlineCount()
{
_inlineCount = true;

0 comments on commit dd8b2fc

Please sign in to comment.