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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:28:25+00:00 2026-06-06T18:28:25+00:00

I am building a test application using MVC3, Razor, and Entity Framework 4.1 with

  • 0

I am building a test application using MVC3, Razor, and Entity Framework 4.1 with a schema-first approach (as apposed to a code-first approach), in a repository pattern. I would like to avoid accessing data objects in my view, and access a model instead, but I am having a problem. As far as I can tell, the data objects are being returned from the data layer as ObjectSet, but my View needs IEnumerable, and I don’t know how to cast one to the other.

Here is some code, to help clarify.


Model …

namespace TestSolution.Models
{
    public class ProjectModel
    {
        [HiddenInput]
        public int Id { get; set; }

        [Required]
        [StringLength(255, ErrorMessage = "The name cannot be more than 255 characters long.")]
        [Display(Name = "Name")]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Description")]
        public string Description { get; set; }
    }
}

Repository …

public IQueryable<ProjectModel> GetProjects()
{
    return Db.Project;
}

Entities …

public ObjectSet<Project> Project
{
    get
    {
        if ((_Project == null))
        {
            _Project = base.CreateObjectSet<Project>("Project");
        }
        return _Project;
    }
}

Controller …

public ActionResult Index()
{
    IEnumerable<TestSolution.Models.ProjectModel> model = _projectRepository.GetProjects();
    return View(model);
}

View …

@model IEnumerable<TestSolution.Models.ProjectModel>

Error I am getting when building …

Cannot implicitly convert type 'System.Data.Objects.ObjectSet<TestSolution.Project>' to 'System.Linq.IQueryable<TestSolution.Models.ProjectModel>'. An explicit conversion exists (are you missing a cast?)

Does this question make sense? I am just not sure where go from here … any advise you guys can give me would be awesome. 🙂

EDIT: I was able to solve this with Kyle’s suggestion by changing my Repository code to …

public IQueryable<ProjectModel> GetProjects()
{
  return Db.Project.Select(i => new ProjectModel() { Id = i.Id, Name = i.Name, Description = i.Description });
}
  • 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-06-06T18:28:27+00:00Added an answer on June 6, 2026 at 6:28 pm

    The problem isn’t converting from ObjectSet<T> to IEnumerable<T> (ObjectSet<T> implements IEnumerable<T>).

    The problem is converting from TestSolution.Project to TestSolution.Models.ProjectModel. You will need to write some conversion code, maybe something similar to the below:

    model.Select(i => new ProjectModel() { /* Set properties here. */ });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a unit test suite for my application, using QTestLib . It's
I am building an application using django, and using django-south for the database schema
We are building a comprehensive integration test framework in C# for our application which
I'm building a application that sends a test message to another email, the program
I've been building my sample asp.net application using VWD2008 and the development virtual server
I am building a Web Application in ASP.NET 4.0, using VS 2010 Professional. I
I'm building an application that works with the db of another application, using mssql
I am using Rational Application Developer v7.0 that ships with an integrated test environment.
I'm building mvc3 application that should serve about 1000-2000 concurrent users, I implemented Castle
I'm building an application using OpenJPA 2.0.0, Jersey 1.3, and JUnit 4.8.1. I've set

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.