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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:20:53+00:00 2026-05-26T20:20:53+00:00

Here is the method: public IEnumerable<???> GetAllSiteVisits() { var visits = _db.STEWARDSHIP .OrderByDescending(r =>

  • 0

Here is the method:

public IEnumerable<???> GetAllSiteVisits()
{
    var visits =
        _db.STEWARDSHIP
           .OrderByDescending(r => r.VISIT_DATE)
           .Select(r => new
               {
                   id = r.STEWARDSHIP_ID,
                   name = r.SITE.SITE_NAME,
                   visit_date = r.VISIT_DATE,
                   visit_type = r.VISIT_TYPE_VAL.VISIT_TYPE_DESC
               });
    return visits;
}

I am using the Entity Framework 4.2.

So the problem is figuring out the return type. If I were just to use the info directly from the DB table, I’d return IEnumerable<STEWARDSHIP> but since I am selecting only certain fields, I don’t understand what the return type is.

  • 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-26T20:20:54+00:00Added an answer on May 26, 2026 at 8:20 pm

    Return type will be a collection of AnonymousType where each item represents a class with the following properties:

    • id (with type of the r.STEWARDSHIP_ID)
    • name (with type of the r.SITE.SITE_NAME)
    • visit_date (with type of the r.VISIT_DATE)
    • visit_type (with type of the r.VISIT_TYPE_VAL.VISIT_TYPE_DESC)

    Then you can loop through the elements using foreach loop:

    foreach(var item in visits)
    {
       string visitInfo = String.Format(
                            CultureInfo.InvariantCulture,
                            "Id: {0}, Name: {1}, Date: {2}, Type: {3}",
                            item.id,
                            item.name,
                            item.visit_date,
                            item = visit_type);
    
       Debug.WriteLine(visitInfo);       
    }
    

    If you need to return results of the query from the method you can introduce a new class which represent these fore properties:

    // TODO: update types of the properties
    class VisitDetails
    {
       public string Id { get; private set; }
       public string Name { get; private set; }
       public DateTime VisitDate { get; private set; }
       public string VisitType { get; private set; }
    }
    

    And update query to create instances of VisitDetails rather than Anonymous Type:

    .Select(r => new VisitDetails
        {                      
            Id = r.STEWARDSHIP_ID,                      
            Name = r.SITE.SITE_NAME,
            VisitDate = r.VISIT_DATE,
            VisitType = r.VISIT_TYPE_VAL.VISIT_TYPE_DESC                  
        });   
    

    In this way return type would be IEnumerable<VisitDetails> so you easily can even return results of the query itself from the method by specifying exact return type as well so code would be much clean.

    See Object Initializers with anonymous types for more details.

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

Sidebar

Related Questions

here's the method: public static int chooseStrat () { String[] strats = new String[1]
Here's the method i want to write: public static IEnumerable<String> GetTableNames(this IQueryable<T> query) {
Consider this method: public IEnumerable<T> GetList(int Count) { foreach (var X in Y) {
Here's the method: public static String CPUcolor () { System.out.println (What color am I?)
Here's my extension method for invoke on a control: public static void Invoke<T>(this T
I have a method which requests external webservices and returns json here: public string
I have a generic method (in a non generic class) returning elements. public IEnumerable<T>
I wrote this extension method (which compiles): public static IEnumerable<J> Flatten<T, J>(this IEnumerable<T> @this)
I have the following method that creates a csv. var csv = new CsvResult<MatrixCampaignLine>(matrixCampaignLines,
I have the following service interface: public interface IGrantApplicationService { IEnumerable<T> GetAll(); } Here

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.