I just downloaded RavenDB Build 499 and
store.Conventions.QueryEnumsAsIntegers is working great.
Have you considered maybe changing it to a setting like
store.Conventions.SaveEnumsAsIntegers that would do both saving and
querying of enums as integers? Since one without the other doesn't
make sense.
-Ryan
On Oct 7, 11:44 am, rfuller <
rful...@gmail.com> wrote:
> Awesome. Thanks!
>
> On Oct 7, 4:19 am, Ayende Rahien <
aye...@ayende.com> wrote:
>
>
>
>
>
>
>
> > store.Conventions.QueryEnumsAsIntegers = true;
>
> > As of the next build.
>
> > On Thu, Oct 6, 2011 at 8:25 PM, rfuller <
rful...@gmail.com> wrote:
> > > Itamar,
> > > That's what I was doing. It was a "JsonConverter" though, not
> > > "ITypeConverter". I wrote my own replacement for the default
> > > JsonEnumConverter and set it up like this:
>
> > > documentStore.Conventions.CustomizeJsonSerializer =
> > > jsonSerializer =>
> > > {
>
> > > jsonSerializer.Converters.Remove(jsonSerializer.Converters.Where(c =>
> > > c.GetType() == typeof(JsonEnumConverter)).First());
> > > jsonSerializer.Converters.Add(new
> > > CustomJsonEnumConverter());
> > > };
>
> > > Once I did this enums then were saved and loaded correctly as ints.
> > > HOWEVER I lost the ability to query them with linq.
>
> > > var offProducts = session.Query<Product>().Where(p => p.MyEnum ==
> > > TestEnum.Off).ToList();
>
> > > Linq queries using theenumdon't work. This query would return no
> > > results even if there are matching documents.
>
> > > I don't understand how implementing your own custom JsonConverter is
> > > useful if it renders that Type unqueryable (or is this just a quirk of
> > > theenumtype specifically?).
>
> > > If I did something wrong let me know. You mentioned ITypeConverter
> > > instead of JsonConverter. How would this be done using
> > > ITypeConverter?
>
> > > -Ryan
>
> > > On Oct 6, 1:49 pm, Itamar Syn-Hershko <
ita...@hibernatingrhinos.com>
> > > wrote:
> > > > You should probably use ITypeConverter then, to convert Enums to their
> > > int
> > > > representation and back
>
> > > > On Thu, Oct 6, 2011 at 6:34 PM, rfuller <
rful...@gmail.com> wrote:
> > > > > Personal preference. Persisting enums as numbers makes refactoring
> > > > > easier. I think of enums as a number with a human readable label
> > > > > attached. Persisting them as this number means I'm free to change the
> > > > > label as I (or the client) sees fit. For example if I decide that my
> > > > > On/Offenumshould instead be called Active/Inactive then if theenum
> > > > > number is persisted it's a really easy change (right click in visual
> > > > > studio and rename). If theenumstring is persisted, as in RavenDB,
> > > > > I'd have to update all existing documents. In most of my enums the
> > > > > number is completely arbitrary, and so has no reason to ever change.
> > > > > The label part is much more likely to change as I develop my program.
> > > > > Basically, If you persist anenumas a string then the number
> > > > > component becomes very easy to change. If you persist anenumas a
> > > > > number then the string component becomes very easy to change. I'd
> > > > > rather the string part be easy to change. And I don't really care
> > > > > about readability of the raw json document itself. No end user will
> > > > > ever see it, and I probably won't look at the raw json document that
> > > > > much either once I've gotten comfortable with RavenDB.
>
> > > > > -Ryan
>
> > > > > On Oct 6, 6:50 am, Ayende Rahien <
aye...@ayende.com> wrote:
> > > > > > RavenDB currently assumes the default behavior.
> > > > > > Why are you trying to persist it like an int?
>
> > > > > > On Wed, Oct 5, 2011 at 8:31 PM, rfuller <
rful...@gmail.com> wrote:
> > > > > > > I don't want to treat it like an int. I want to treat it like an
> > >enum
> > > > > > > and just persist it as an int. Just like normally you don't treat
> > > it
> > > > > > > as a string. You treat it like anenumand Raven just persists it