使用 RavenDB 自动生成的索引抛出错误。
主要错误行是:
第 25 行,位置 4:错误 CS1593 - 委托 'System.Func>' 不接受 1 个参数
第 29 行,位置 5:错误 CS0833 - 匿名类型不能有多个同名属性
完整的错误消息包含在附件中。
这是代码:
class Program
{
static void Main(string[] args)
{
var documentStore = new DocumentStore
{
Url="http://localhost:8080/databases/test"
};
documentStore.Initialize();
var bookName = "Book";
using (var session = documentStore.OpenSession())
{
session.Store(new Book
{
Name = bookName,
Posts = new List<BookPost> {new BookPost()
{
Title = "A post",
Type = BookPost.BookPostType.BooPost1
}
}
});
session.Store(new Book
{
Name = bookName,
Posts = new List<BookPost> {new BookPost()
{
Title = "A post",
Type = BookPost.BookPostType.BooPost2
}
}
});
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
var ravenQueryable = session.Query<Book>().Customize(b=>b.WaitForNonStaleResultsAsOfLastWrite()).ToList();
}
using (var session = documentStore.OpenSession())
{
var bookToGet = new List<string>() {bookName};
var bookPostToGet = new List<BookPost.BookPostType?> {BookPost.BookPostType.BooPost1};
var books = session.Query<Book>().Where(b => b.Name.In(bookToGet));
books = books.Where(b => b.Posts.Any(p => p.Type.In(bookPostToGet)));
//****** This line throws an error *********//
var bookPage = books.ToList();
}
}
}
public class Book
{
public String Name { get; set; }
public List<BookPost> Posts { get; set; }
}
public class BookPost
{
public string Title { get; set; }
public BookPostType? Type { get; set; }
public enum BookPostType
{
BooPost1,
BooPost2,
BooPost3
}
}
尝试使用更新的版本:RavenDb 构建 RavenDB.Client.2.5.2666 和 RavenDB.Client.2.5.2666。
完整的解决方案(带有 RavenDb 包:)可在我的github 上找到。