Closed cecilphillip closed 9 years ago
If you're using a loose schema, you can use an IDictionary<string, object> as your type and expressions will work on a dictionary like you'd expect (see https://github.com/mfenniak/rethinkdb-net/blob/master/rethinkdb-net-test/Integration/NamedValueDictionaryTests.cs#L269 for examples).
I'd generally advise separating the "core fields" and the flexible fields, so that you'd have a schema with typed fields and then an IDictionary<string, object> field that contains all of the loose fields. With this approach, you get C# type safety where you can, and no lost functionality where you have less defined data.
That works. Thanks.
In case anyone want's to know how this map reduce ReSQL query converted into C#, here's what it looks like
var today = DateTime.Now.Date;
var query = _table.Group(evt => evt.EventType)
.Map(e => new
{
count = 1,
today = (e.DateCreated.Day == (today.Day) &&
e.DateCreated.Month == (today.Month) &&
e.DateCreated.Year == (today.Year)) ? 1 : 0,
month = (e.DateCreated.Month == (today.Month) &&
e.DateCreated.Year == (today.Year)) ? 1 : 0,
})
.Reduce((left, right) => new
{
count = left.count + right.count,
today = left.today + right.today,
month = left.month + right.month
});
var result = conn.Run(query);
I have some ReQL that looks something like this
Now this far I have been storing my documents using JObjects. So my query objects look like following:
I use JObjects because my schemas are very loose with the exception of some core fields. I can't seem to do a group or filter on JObjects. I get an error that pretty much says the expression could not be evaluated, e.g.
_table.Group(evt => evt["event_type"]);
Is there another way that I could query/filter on the data? Is there a non generic ITableQuery that I could use ?