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 926773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:44:26+00:00 2026-05-15T19:44:26+00:00

I have a repository: public ObservableCollection<ProjectExpenseBO> GetProjectExpenses() { //Get by query IQueryable<ProjectExpenseBO> projectExpenseQuery =

  • 0

I have a repository:

public ObservableCollection<ProjectExpenseBO> GetProjectExpenses()
{
    //Get by query
    IQueryable<ProjectExpenseBO> projectExpenseQuery =
       from p in _service.project_expense
       from e in _service.vw_employee 
       where p.employee_id == e.employee_id 
       select new ProjectExpenseBO()
       {
           ProjectExpenseID = p.project_expense_id
           , EmployeeID = p.employee_id
           , ProjectNumber = p.project_number
           , PurchaseTypeID = p.purchase_type_id
           , BuyerEmployeeID = p.buyer_employee_id
           , PurchaseOrderNumber = p.purchase_order_number
           , DeliveryDate = p.delivery_date
           , EmployeeName = e.first_name + " " + e.last_name
       };

    ObservableCollection<ProjectExpenseBO> projectExpenseCollection = new ObservableCollection<ProjectExpenseBO>(projectExpenseQuery);
    return projectExpenseCollection;
}

I am wondering if it is better to return an IList or IEnumerable (instead of an ObservableCollection) from my repository since my viewmodel may end up putting it in either an ObservableCollection or List, depending on my need. For instance, I may return data from the repository above to a read-only datagrid or dropdown list, or I may want the same data in an editable datagrid.

I am thinking (and could be wrong) that I want my repository to return a barebones list, then convert it to what suites my needs in the viewmodel. Is my thinking correct? Here is what I was thinking:

public IEnumerable<ProjectExpenseBO> GetProjectExpenses()
{
    //Get by query
    IQueryable<ProjectExpenseBO> projectExpenseQuery =
       from p in _service.project_expense
       from e in _service.vw_employee 
       where p.employee_id == e.employee_id 
       select new ProjectExpenseBO()
       {
           ProjectExpenseID = p.project_expense_id
           , EmployeeID = p.employee_id
           , ProjectNumber = p.project_number
           , PurchaseTypeID = p.purchase_type_id
           , BuyerEmployeeID = p.buyer_employee_id
           , PurchaseOrderNumber = p.purchase_order_number
           , DeliveryDate = p.delivery_date
           , EmployeeName = e.first_name + " " + e.last_name
       };
    return projectExpenseQuery;
}

Thanks.

  • 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-15T19:44:27+00:00Added an answer on May 15, 2026 at 7:44 pm

    I would personally return an IEnumerable<T> or IList<T> instead of ObservableCollection. There are many times when you may not need the full behavior of ObservableCollection<T>, in which case you’re putting more resources than necessary.

    I like your second implementation – however, be aware that there is one potential downside. Some people don’t like returning deferred execution IEnumerable<T> from a repository, since it defers execution until usage. While it has the upside of potentially saving resources, especially if you end up not using some or all of the enumerable, this can lead to an exception occuring later (when the IEnumerable<T> is actually used), instead of occuring within your repository yourself.

    If this bothers you, you could just force the execution to occur (ie: call ToList() or similar).

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

Sidebar

Related Questions

No related questions found

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.