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

  • Home
  • SEARCH
  • 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 4015902
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:40:31+00:00 2026-05-20T09:40:31+00:00

Lets say that I need to execute this query with EF in business layer

  • 0

Lets say that I need to execute this query with EF in business layer

var list = context.Invoices.Select(x => new
{
    InvoiceNumber = x.InvoiceNUmber,
    InvoiceDate = x.InvoiceDate,
    CustomerName = x.Customer.CustomerName,
    TotalValue = x.InvoiceData.Sum(y => y.Quantity * y.Price),
    Id = x.Id
}).ToList();

What can I do for this list to be easily sortable, searchable or filterable in UI layer?

Thanks,
Goran

  • 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-20T09:40:31+00:00Added an answer on May 20, 2026 at 9:40 am

    The way to do it is to return a object that is not anonymous. That is, create a class to hold this data. It should either have an implicit zero-argument constructor (because you have no constructors), or an explicit zero-argument one (because you have defined other constructors). Then you can say:

    List<MyObject> list = context.Invoices.Select(x => new MyObject()
    {
        InvoiceNumber = x.InvoiceNUmber,
        InvoiceDate = x.InvoiceDate,
        CustomerName = x.Customer.CustomerName,
        TotalValue = x.InvoiceData.Sum(y => y.Quantity * y.Price),
        Id = x.Id
    }).ToList();
    

    Now you can return the strongly-typed list of objects out of your business layer, and your UI layer can use LINQ (or whatever) to do sorting/filtering/paging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my scenario. For the example lets say that I need to return
I have one field that I need to sum lets say named items However
Lets say I have a class like this: Class User { var $id var
Lets say there are multiple functions throughout my program that need to append data
My problem is this: I need to select values from groups table that do
Let's say that for some reason you need to write a macro: MACRO(X,Y) .
Let's say I have an integer that I need to convert to a string
Lets say that you have websites www.xyz.com and www.abc.com. Lets say that a user
Lets say that I have a header user control in a master page, and
My simplified and contrived example is the following:- Lets say that I want to

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.