Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:37+00:00 2026-05-27T17:27:37+00:00

Scenario: Parent-child relationship between CustomerOrders & CustomerOrderItems in db. Both CustomerOrders and CustomerOrderItems are

  • 0

Scenario:

Parent-child relationship between CustomerOrders & CustomerOrderItems in db.

Both CustomerOrders and CustomerOrderItems are defined in the auto-generated Linq2Sql dbml class.

MVC Code:

I have a view model class:

public class OrdersListViewModel
{
    public IEnumerable<CustomerOrder> CustomerOrders { get; set; }
    public PagingInfo PagingInfo { get; set; }
}

which passes data to a partial view (only interested in the CustomerOrders data):

@model CallTracking.Domain.Concrete.CustomerOrder
<tr>
    <td>@Model.Auto_ID</td>
    <td>@Model.OrderTotal</td>
    <td>@string.Format("{0} {1}", Model.CustomerFirstName, Model.CustomerSecondName)</td>
    <td>@Model.Email</td>
    **<td>@Model.CustomerOrderItems.OrderByDescending(i => i.SalesPrice).FirstOrDefault().ItemName</td>**
</tr>

This works fine, the problem is that I’ve used a Linq expression in order to display the highest value orderitem for each order record, but I feel (and have read) that I shouldn’t use Linq in the view and this should be a property in the view model i.e.

public CustomerOrderItem HighestValueOrderItem { get; set; }

It’s at this point where I get stuck – how & where would I set this value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:27:37+00:00Added an answer on May 27, 2026 at 5:27 pm

    In CustomerOrder Model Create Property Called

    private CustomerOrderItem _HighestValueOrderItem = null;
    public CustomerOrderItem HighestValueOrderItem { 
    get{
       if(this.CustomerOrderItems.Any() && _HighestValueOrderItem != null){
            _HighestValueOrderItem =  this.CustomerOrderItems.OrderByDescending(i => i.SalesPrice).FirstOrDefault();
            return  _HighestValueOrderItem;
       } else {
          return new CustomerOrderItem();
       }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation where I have a parent child relationship between two sets
I got a scenario like this Class Parent { Property A; } Class A
It's obvious that a parent class's object can hold a reference to a child,
I have a parent to child relationship. My problem is, when I access the
Scenario: I have the following structure; Group (parent) -> Item (child). A Group can
I have a scenario where I have a parent class with some definitions we
I want to use constraints in SQLite. Scenario: Stop parent delete if child is
I have common parent\children scenario: public class Order : AdvancedBaseOrder { ICollection<ProducerRelation> producers =
I have a UIPopoverController with a subclass UINavigationController. Both the parent and child views
In my Parent Child scenario, I need to get the custom list of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.