Note that there are some explanatory texts on larger screens.

plurals
  1. POOuerying an object inside ravendb document
    primarykey
    data
    text
    <p>There is a doubt as of how to query or retrieve a value from an object stored in an document as follows in raven db.</p> <pre><code>class User { public String Id { get; set; } public AccountType AccountType { get; set; }Servicetax public String MainAccountMobileNo { get; set; } public UserStatus Status { get; set; } public String EmailId { get; set; } public String DisplayName { get; set; } public Object User { get; set; } } </code></pre> <p>Here i am storing three different types of classes into the object User. Say Customer,Retailer and Trader. </p> <pre><code>Customer { public String Name{ get; set; } public String Address { get; set; } public String MobileNo { get; set; } public String EmailId { get; set; } } </code></pre> <p>Retailer</p> <pre><code>{ public String Name{ get; set; } public String Address { get; set; } public String MobileNo { get; set; } public String EmailId { get; set; } } </code></pre> <p>Trader</p> <pre><code>{ public String Name{ get; set; } public String Address { get; set; } public String MobileNo { get; set; } public String EmailId { get; set; } } </code></pre> <p>Now is it possible to retrieve results based on the Customer's class detail? That is now i want to retrieve All the Customers based on Address in the customer class, So how will i do it? How to typecast the object user in the query to type customer. Thanks.<img src="https://i.stack.imgur.com/970ix.png" alt="Image of my document storage"></p> <p>The user object in the document can store any type of class's object like account info trader in the above image. So how can i query from the object type that cannot is not definite and changing.</p> <p><code>var Result = sess.Query&lt;UserAccountInfo&gt;().Where(x =&gt; x.AccountType == usertype &amp;&amp; ((AccountInfoCustomer)x.User).Customerstatus == CustomerStatus.Pending);</code> </p> <blockquote> <p>This is the query that's been tried and this is the exception that's been caught {"Url: \"/indexes/dynamic/UserAccountInfos?query=AccountType%253ADistributor%2520AND%2520User).Customerstatus%253APending&amp;start=0&amp;pageSize=128&amp;aggregation=None\"\r\n\r\nSystem.ArgumentException: The field ')_Customerstatus' is not indexed, cannot query on fields that are not indexed\r\n at Raven.Database.Indexing.Index.IndexQueryOperation.AssertQueryDoesNotContainFieldsThatAreNotIndexes()</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload