RavenDB queries nullable enums by enum value (number) instead of enum name (string)

50 views
Skip to first unread message

alwin

unread,
Feb 6, 2012, 2:02:07 AM2/6/12
to ravendb
Query by enum works, but query by nullable enum does not work...
It turns the enum value into a number, but the value is stored as a
string in the document.

Example of failing test here: http://pastebin.com/tAZx3nsB


public class RavenDB_NullableEnum : RavenDbTestBase
{
public class ModelWithEnum
{
public MonitorCategory Category { get; set; }
public MonitorCategory? NullableCategory { get; set; }
}

public enum MonitorCategory
{
Normal,
WideScreen
}

/// <summary>
/// works
/// </summary>
[Fact]
public void CanQueryByEnum()
{
using (var session = OpenSession())
{
session.Store(new ModelWithEnum { Category =
MonitorCategory.Normal });
session.SaveChanges();
}

using (var session = OpenSession())
{
var fromDb = session.Query<ModelWithEnum>().FirstOrDefault(m =>
m.Category == MonitorCategory.Normal);
Assert.NotNull(fromDb);
}
}

/// <summary>
/// fails
/// Executing query 'NullableCategory:0'
/// Should be: Executing query 'NullableCategory:Normal' I think?
/// </summary>
[Fact]
public void CanQueryByNullableEnum()
{
using (var session = OpenSession())
{
session.Store(new ModelWithEnum { NullableCategory =
MonitorCategory.Normal });
session.SaveChanges();
}

using (var session = OpenSession())
{
var fromDb = session.Query<ModelWithEnum>().FirstOrDefault(m =>
m.NullableCategory == MonitorCategory.Normal);
Assert.NotNull(fromDb);
}
}

/// <summary>
/// works
/// </summary>
[Fact]
public void CanQueryByNullableEnumThatIsNull()
{
using (var session = OpenSession())
{
session.Store(new ModelWithEnum { NullableCategory = null });
session.SaveChanges();
}

using (var session = OpenSession())
{
var fromDb = session.Query<ModelWithEnum>().FirstOrDefault(m =>
m.NullableCategory == null);
Assert.NotNull(fromDb);
}
}
}

Oren Eini (Ayende Rahien)

unread,
Feb 6, 2012, 8:20:45 AM2/6/12
to rav...@googlegroups.com
Thanks, fixed.
Reply all
Reply to author
Forward
0 new messages