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);
}
}
}