craiggwilson / Simple.Data.MongoDB

MongoDB adapter for Simple.Data
35 stars 10 forks source link

Embedded array problem #15

Open pbagh opened 11 years ago

pbagh commented 11 years ago

Hi,

Updating a document containing array types seems to be broken. Initial insertion works as expected but when the document is updated the array type is no longer stored in its original form. The update stores additional type information for the array member (_t System.Int32[]) which causes subsequent retrievals to return null for the array type.

Sample:

using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks;

using Simple.Data; using Simple.Data.MongoDB; using MongoDB.Bson;

namespace ConsoleApplication1 { class Program { class TestArray { public string Id { get; set; } public int[] Ints { get; set; } }

    static void Main(string[] args)
    {
        dynamic db = Database.Opener.OpenMongo("mongodb://fn101devz01/Test");

        TestArray test_array =
            new TestArray
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Ints = new int[] { 0, 1, 2 }
            };

        db.Test.Insert(test_array);
        test_array = db.Test.All().First();
        // Causes additional type info to be stored
        db.Test.Update(test_array);
        // Array member is null
        test_array = db.Test.All().First();
    }
}

}

Thanks,

Patrick

craiggwilson commented 11 years ago

I'll take a look and see what I come up with...