diff --git a/src/OpenRiaServices.Client/Framework/EntityRef.cs b/src/OpenRiaServices.Client/Framework/EntityRef.cs
index cc6dfc0c..9d89d348 100644
--- a/src/OpenRiaServices.Client/Framework/EntityRef.cs
+++ b/src/OpenRiaServices.Client/Framework/EntityRef.cs
@@ -223,8 +223,11 @@ private bool Filter(TEntity entity)
/// The entity or null.
private TEntity GetSingleMatch(IEnumerable entities)
{
+ IEnumerable enumerable = (entities as ICollection)
+ ?? entities.OfType();
+
TEntity entity = null;
- foreach (TEntity currEntity in entities.OfType().Where(this.Filter))
+ foreach (TEntity currEntity in enumerable.Where(this.Filter))
{
if (entity != null)
{
@@ -281,8 +284,8 @@ private void MonitorEntitySet()
/// The collection changed event arguments.
private void SourceSet_CollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
- if (this._parent.EntityState != EntityState.New &&
- args.Action == NotifyCollectionChangedAction.Add)
+ if (args.Action == NotifyCollectionChangedAction.Add
+ && this._parent.EntityState != EntityState.New)
{
TEntity newEntity = this.GetSingleMatch(args.NewItems);
if ((newEntity != null) && (newEntity != this._entity))
@@ -294,7 +297,7 @@ private void SourceSet_CollectionChanged(object sender, NotifyCollectionChangedE
}
else if (args.Action == NotifyCollectionChangedAction.Remove)
{
- if (this._entity != null && args.OldItems.OfType().Contains(this._entity))
+ if (this._entity != null && args.OldItems.Contains(this._entity))
{
// if the referenced Entity has been removed from the source EntitySet,
// we need to clear out our cached reference and raise the notification