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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:04:14+00:00 2026-05-23T12:04:14+00:00

Im trying to return a list to a display template containing data from two

  • 0

Im trying to return a list to a display template containing data from two tables, i am using the repository pattern, and a viewmodel to pass the data to the view from a LINQ query that returns both objects

is there to define a collection of multiple types in the interface?
For a single type i have used this in the interface,

    IQueryable<CustomerSite> CustomerSites { get; }

then i have my linq query in the repository

public IQueryable<CustomerSite> CustomerSites
    {
        get { return customerSitesTable; }
    }

However since this new query will contain 2 types, both customers and customer sites, how should this collection be defined in the interface?

======UPDATE

I have tried using the .Include (this throws an error stating that there is no definition for include in the Customer entity, not sure if im missing a name space for this?)

I have also tried creating a custom interface,

public interface ICustomersAndSitesRepository
{
    IQueryable<CustomerSite> CustomerSites { get; }
    IQueryable<Customer> Customers { get; }
    IQueryable<ICustomersAndSitesRepository> CustomerAndSites { get; }
}

And this method in the repository

public IQueryable <ICustomersAndSitesRepository> CustomerAndSites
    {
        get { return CustomerAndSites; }
    }

However when i try to pass the collection to the view in the controller like,

public ViewResult List([DefaultValue(1)] int page)
    {

        var customersWithSitesToShow = customersAndSitesRepository.CustomerAndSites;
        var viewModel = new CustomerSitesListViewModel
        {                
            Customers = customersWithSitesToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList(),
            PagingInfo = new PagingInfo
            {
                CurrentPage = page,
                ItemsPerPage = PageSize,
                TotalItems = customersWithSitesToShow.Count()
            }
        };

        return View(viewModel);  //Passed to view as ViewData.Model (or simply model)
    }

I get a conversion error re convreting the repostiory to the view model

Cannot implicitly convert type  'System.Collections.Generic.List<CustomerDatabase.Domain.Abstract.ICustomersAndSitesRepository>' to 'System.Collections.Generic.IEnumerable<CustomerDatabase.WebUI.Models.CustomerViewModel>'. An explicit conversion exists (are you missing a cast?)  

Im defining the viewmodel like

public IEnumerable Customers { get; set; }

Can anyone kindly point me in the right direction?

  • 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-23T12:04:14+00:00Added an answer on May 23, 2026 at 12:04 pm

    Assuming that a Customer has many CustomerSite then you’d return an IQueryable<Customer> but use .Include to return the CustomerSites within each Customer.

    e.g.

    public IQueryable<Customer> GetCustomersAndSites()
    {
        return MyEntities.Customers.Include("CustomerSite");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a list to return some JSON data to a view. Following
I'm trying to return a transparent GIF from an .aspx page for display within
I am trying to return an array Data Member from one smaller 2D Array
I am trying to fetch data from my database and when I display it
I am trying to return a list of images as bytes to display on
Im trying to display two list: one for categories and brand but only the
I'm trying to write some JQuery using the AutoComplete plugin to display a list
I'm trying to get a list of values to display upon a selection from
I'm trying to display a list of global validation errors in my freemarker template
I'm trying to display a list of projects using backbone.js. Basically, backbone should be

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.