Note that there are some explanatory texts on larger screens.

plurals
  1. POData reference in mongodb
    text
    copied!<p>I have two model calss user and product and i have common property productId. i want fetch the user data from Mongodb. I want to fetch user coreesponding to the product under him which should be displayed.</p> <p>user model</p> <p>public class User : Product {</p> <pre><code> [BsonId] public string GuId { get; set; } public string Name { get; set; } public string EMailAddress { get; set; } public string ProductId { get; set; } } </code></pre> <p>product model</p> <p>public class Product {</p> <pre><code> [BsonId] public int Id { get; set; } public string ProductId { get; set; } public string ProductName { get; set; } } </code></pre> <p>And my application layer has below code:-</p> <pre><code> public IEnumerable&lt;User&gt; GetAllUsers() { // var users = new User(); IList&lt;User&gt; itemCollection = new List&lt;User&gt;(); var itemIdList = new List&lt;string&gt;(); itemCollection = _users.Include&lt;User&gt;.Load(itemIdList.ToArray()) .OrderByDescending(x =&gt; x.LastUpdatedDate).ToList(); // var itemCollection = _users.Load&lt;User&gt;(itemIdList.ToArray()); this.LoadItemStatusDefinitions(itemCollection); var users = _users. FindAll(). SetSortOrder(SortBy.Descending("createdate")); return users; } private void LoadItemStatusDefinitions(IEnumerable&lt;User&gt; items) { // iterates through each items in the collection. foreach (var item in items) { // check whether status definition is already assigned to the item if (!string.IsNullOrEmpty(item.ProductId)) { // loading the status definition associated with each item var statusDefinition = _users.Load&lt;Product&gt;(item.ProductId); if (statusDefinition != null) { // assign the status definition to the item. item.ProductId = statusDefinition; } } } } </code></pre>
 

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