Skip to content

Instantly share code, notes, and snippets.

@mattjohnsonpint
Created February 1, 2013 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattjohnsonpint/4692351 to your computer and use it in GitHub Desktop.
Save mattjohnsonpint/4692351 to your computer and use it in GitHub Desktop.
Example for SO Q14644619
using System.Diagnostics;
using System.Linq;
using Raven.Tests.Helpers;
using Xunit;
namespace RavenTests.StackOverflow
{
public class Q14644619 : RavenTestBase
{
public class UserAccountInfo
{
public string Id { get; set; }
public object User { get; set; }
}
public class AccountInfoCustomer
{
public CustomerStatus CustomerStatus { get; set; }
}
public enum CustomerStatus
{
Pending,
New,
Old,
Dead
}
[Fact]
public void Test()
{
using (var documentStore = NewDocumentStore())
{
using (var session = documentStore.OpenSession())
{
session.Store(new UserAccountInfo { User = new AccountInfoCustomer { CustomerStatus = CustomerStatus.Pending } });
session.Store(new UserAccountInfo { User = new AccountInfoCustomer { CustomerStatus = CustomerStatus.Pending } });
session.Store(new UserAccountInfo { User = new AccountInfoCustomer { CustomerStatus = CustomerStatus.Dead} });
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
var q = session.Query<UserAccountInfo>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => ((AccountInfoCustomer) x.User).CustomerStatus == CustomerStatus.Pending);
Debug.WriteLine(q);
var results = q.ToList();
Assert.Equal(2, results.Count);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment