我是 RaveDB 的新手(实际上我昨天才开始学习它)。并尝试实现一些功能。
让我们有下一个类层次结构:
public abstract class Transaction
{
    public string Id { get; set; }
}
public class CategoryTransaction : Transaction
{
    public string AccountId { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
    public decimal Amount { get; set; }
}
public class ExchangeTransaction : Transaction
{
    public string DebitAccountId { get; set; }
    public string CreditAccountId { get; set; }
    public decimal DebitAmount { get; set; }
    public decimal CreditAmount { get; set; }
}
一切都存储优秀的 int db。我将Conventions = FindTypeTagName ...商店文档添加为“事务/*”文档 ID。
但我想创建索引以选择特定帐户的所有交易(按字段 AccountId)。我创建了索引:
public class AccountTransactionResult
{
    public string AccId { get; set; }
}
public class Account_Transactions : AbstractMultiMapIndexCreationTask<AccountTransactionResult>
{
    public Account_Transactions()
    {
        this.AddMap<CategoryTransaction>( transactions => from transaction in transactions
                                                            select new
                                                                    {
                                                                    AccId = transaction.AccountId
                                                                    } );
        this.AddMap<ExchangeTransaction>( transactions => from transaction in transactions
                                                            select new
                                                                    {
                                                                    AccId = transaction.DebitAccountId
                                                                    } );
        this.AddMap<ExchangeTransaction>( transactions => from transaction in transactions
                                                            select new
                                                                    {
                                                                    AccId = transaction.CreditAccountId
                                                                    } );
    }
}
该索引运行良好,我无法从 DB(Exchange 和 Category)中获取所有类型的事务作为 single IEnumerable<Transaction>。这太棒了。
但我想使用索引仅返回特定帐户的交易。因为ExchangeTransaction可以属于两个Accounts。我想看看ExchangeTransaction两者Accounts。我可以通过 AccId(索引字段)在 Raven Studio 中进行查询,而且效果很好!但我无法在代码中创建相同的请求:(。
有人能帮我吗?如何在 C# LINQ 查询中使用索引字段 AccId?
这段代码
var query = session.Query<Transaction, Account_Transactions>()
返回所有类型的事务,但我不知道如何按数据库中的索引字段过滤事务。
提前致谢。请对不起我的英语,它不是我的母语。