2013-01-17 47 views
0

的,我们试图寻找其他计算器地方&但无法找到一个解决方案。RavenDB查询与Object类型

我们有一个这样的课。

class UserAccountInfo 
{ 
    public String someid; 
    public Object needtoqueryobject; //This can store different object types like AccountInfoCustomer, AccountInfoFriend etc., 
} 

我们想要查询这个类,如下所示。

var Result = sess.Query<UserAccountInfo>().Where(x => ((AccountInfoCustomer)x.needtoqueryobject).AccountType == usertype); 

但是,这是不支持,它说无法对索引字段的查询。我们可以理解,RavenDB无法为这个特定类型编制索引,因为它不了解实际的类型。有人可以解释如何确保这些类也被索引?

添加了AccountInfoCustomer类型定义:

using System; 

namespace Dheutto.Models 
{ 
public enum AccountTypes 
    { 
     Customer, 
     Trader, 
     Distributor 
    } 

    public class AccountInfoCustomer 
    { 
     //The AccountNumber for the document 
     public String FirstName { get; set; } 
     public String MiddleName { get; set; } 
     public String LastName { get; set; } 
     public String Father_spouse_Name { get; set; } 
    public AccountTypes AccountType{ get; set; } 
    } 
} 

这AccountInfoCustomer类型是什么是存储为needtoqueryobject字段对象。所以当我用类型转换进行查询时,我期待它返回一些结果。纠正我,如果我错了。

+0

'对象'没有'AccountType'成员。您需要使用具有该成员的类型。 – Oded

+0

我添加了用于查询的AccountInfoCustomer类型的类定义。这是作为对象存储的内容。所以当我用类型转换进行查询时,我期待它返回一些结果。 – Muthu

+0

这没有帮助。您通过'UserAccountInfo'显示一个不包含'AccountType'或'User'属性的查询。您提供的代码不会编译。您一定没有正确粘贴UserAccountInfo。如果我们看不到问题,我们无能为力。 –

回答

0

如果你在你的实体对象,您无法查询使用LINQ。 您可以查询使用LuceneQuery和无类型语法。