ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

I think DocumentProperty.IgnoreProperty is not working #72

Open sroncolini opened 7 years ago

sroncolini commented 7 years ago

I think DocumentProperty.IgnoreProperty is not working. In sample folder I added a property to class Person

[DocumentProperty(IgnoreProperty = true)]
public string ToIgnore { get; set; }

Then I modified DocumentCommand.InsertMultiple to

      List<Person> persons = new List<Person>
      {
       new Person
       {
        Age = 21,
        Name = "A",
    ToIgnore = "XXX"
       },
       new Person
       {
        Age = 22,
        Name = "B",
    ToIgnore = "YYY"
      }
      };

When executing DocumentCommand.InsertMultiple the property ToIgnore is written to Arango.

It seems the problem is in

CollectionPropertySetting.FindDocumentPropertyForType(string memberName)

where document properties are unconditionally added as

documentProperties.GetOrAdd(memberName, new DocumentPropertySetting());

Since we have no type info in this method, I modified the signature to

FindDocumentPropertyForType(Type type, string memberName) 

This requires a change in

DatabaseCollectionSetting.ChangeDocumentPropertyForType(Type type,string memberName, Action<IDocumentPropertySetting> action)

The change is the following

internal void ChangeDocumentPropertyForType(Type type, string memberName, Action<IDocumentPropertySetting> action)
  {
      ChangeCollectionPropertyForType(type, collection =>
      {
       var collectionSetting = collection as CollectionPropertySetting;

       action(collectionSetting.FindDocumentPropertyForType(type, memberName));
      });

      setting.IdentifierModifier.ClearMethodCache(type);
  }

Then I implemented FindDocumentPropertyForType as

internal IDocumentPropertySetting FindDocumentPropertyForType(Type type, string memberName)
     {

            var documentPropertySetting = DocumentPropertySetting.FindDocumentAttributeForType(type, memberName);
            if (documentPropertySetting == null)
            {
                documentPropertySetting = new DocumentPropertySetting();
            }

            return documentProperties.GetOrAdd(memberName, documentPropertySetting);
     }

Now it works. I don't know if this is the right way to fix it...