Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support for updating and removing items from collections.

  • Loading branch information...
commit 20978698de1a85cc35b060b3dd70d9ca0c62d1f7 1 parent e0cdedb
@craiggwilson authored
Showing with 24 additions and 3 deletions.
  1. +24 −3 src/MongoDB.OData/Typed/TypedUpdateProvider.cs
View
27 src/MongoDB.OData/Typed/TypedUpdateProvider.cs
@@ -1,8 +1,10 @@
using MongoDB.Bson;
using MongoDB.Bson.IO;
+using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Data.Services.Providers;
using System.Linq;
@@ -48,8 +50,10 @@ public object CreateResource(string containerName, string fullTypeName)
var instance = annotation.ClassMap.CreateInstance();
var collection = GetCollection(resourceType);
-
- _actions.Add(() => collection.Insert(resourceType.InstanceType, instance));
+ if (collection != null)
+ {
+ _actions.Add(() => collection.Insert(resourceType.InstanceType, instance));
+ }
_rememberedInstances.Add(instance);
return instance;
@@ -152,6 +156,18 @@ public void SetValue(object targetResource, string propertyName, object property
var resourceType = GetResourceType(targetResource);
var annotation = (TypedResourceTypeAnnotation)resourceType.CustomState;
var memberMap = annotation.ClassMap.GetMemberMap(propertyName);
+ var serializer = memberMap.GetSerializer(memberMap.MemberType) as IBsonArraySerializer;
+ if (serializer != null)
+ {
+ var itemSerializationInfo = serializer.GetItemSerializationInfo();
+ var array = itemSerializationInfo.SerializeValues((IEnumerable)propertyValue);
+ var memberMapSerializationInfo = new BsonSerializationInfo(memberMap.ElementName,
+ serializer,
+ memberMap.MemberType,
+ memberMap.SerializationOptions);
+
+ propertyValue = memberMapSerializationInfo.DeserializeValue(array);
+ }
memberMap.Setter(targetResource, propertyValue);
if (_rememberedInstances.Contains(targetResource))
{
@@ -170,7 +186,12 @@ private MongoCollection GetCollection(ResourceType resourceType)
resourceType = resourceType.BaseType;
}
- var resourceSet = _metadata.ResourceSets.Single(x => x.ResourceType == resourceType);
+ var resourceSet = _metadata.ResourceSets.SingleOrDefault(x => x.ResourceType == resourceType);
+ if (resourceSet == null)
+ {
+ return null;
+ }
+
var state = (TypedResourceSetAnnotation)resourceSet.CustomState;
return state.GetCollection(_currentDataSource);
}
Please sign in to comment.
Something went wrong with that request. Please try again.