I am new to RavenDB and looking for guidance on the correct way to store data printed from data. I have a type with a list of key / value pairs. The type of the value property is unknown at design time.
public class DescriptiveValue { public string Key { get; set; } public object Value { get; set; } }
When I request a DescriptiveValue that was saved using DateTime or Guid Value, the deserialized data type is a string. Numeric values ββretain their data types.
Is there an elegant solution to save a data type or just save all values ββas strings? If I go along the string route, it will limit me when I later want to sort and filter this data (probably through indexes?)
I hope this is a common problem that can be easily solved, and I just think the problem is wrong. Your help is much appreciated!
UPDATE : The result of this unit test is: Assert.AreEqual failed. Expected: <2/2/2012 10:00:01 AM (System.DateTime)>. Actual: <2012-02-02T10: 00: 01.9047999 (System.String)>.
[TestMethod] public void Store_WithDateTime_IsPersistedCorrectly() { AssertValueIsPersisted<DateTime>(DateTime.Now); } private void AssertValueIsPersisted<T>(T value) { ObjectValuedAttribute expected = new ObjectValuedAttribute() { Value = value }; using (var session = this.NewSession()) { session.Store(expected); session.SaveChanges(); } TestDataFactory.ResetRavenDbConnection(); using (var session = this.NewSession()) { ObjectValuedAttribute actual = session.Query<ObjectValuedAttribute>().Single(); Assert.AreEqual(expected.Value, actual.Value); } }
I would expect the actual value of DateTime.
source share