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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:51:28+00:00 2026-05-12T18:51:28+00:00

I’m trying to pass a custom shaped class to a view, but I’m having

  • 0

I’m trying to pass a custom shaped class to a view, but I’m having a little trouble.

This is the error I’m getting.

Cannot implicitly convert type ‘System.Linq.IQueryable’ to ‘Project.Models.TaskTimeLine’. An explicit conversion exists (are you missing a cast?)

This is the first time I’ve added a list to a class, and trying to pass one inside the other as it were.

Here is the class definition

  public class TaskTimeLine
  {
    public Task task { get; set; } // to hold a single object 
    public List<DateTime> scheduledDateTime { get; set; } // to hold a collection of    date times..

  }

The controller action is along the lines of this.

 [Authorize]
    public ActionResult Details2(int id)
    {
        TaskTimeLine task = new TaskTimeLine(); //create new instance of TaskTimeLine
        task = (IQueryable<TaskTimeLine>)taskRepository.GetTaskAndTimeLine(id);

        if (task == null)
            return View("NotFound");
        else
            return View("Details", task);
    }

All quite normal up until now, so I’m guessing maybe something is going wrong here.

  public IQueryable<TaskTimeLine> GetTaskAndTimeLine(int taskId)
    {
       TaskTimeLine taskTimeLine = new TaskTimeLine(); // create new main object
       taskTimeLine.scheduledDateTime = new List<DateTime>(); instanciate list object inside          
       taskTimeLine.task = db.Tasks.SingleOrDefault(d => d.id == taskId); read the record to fill the single task object


       /// Lots of logic is performed here to add loads of date records to the list object.

       /// If I add a break point and check the list I can see that all the date items have gone fine into the collection           


       return (IQueryable<TaskTimeLine>)taskTimeLine;
    }

The only reason I have so many odd casts in places is because it seemed that these helped the program compile. It currently doesn’t compile, but I did get to, but when running the actual request it fails, with the same error message.

Can anyone help, also perhaps with add a more useful title for future people who are stuck with this kind of thing.

  • 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-12T18:51:29+00:00Added an answer on May 12, 2026 at 6:51 pm

    taskTimeLine is a TaskTimeLine; why would it also be an IQueryable<TaskTimeLine>?

      TaskTimeLine taskTimeLine = new TaskTimeLine(); // create new main object
      ....
      return (IQueryable<TaskTimeLine>)taskTimeLine;
    

    IQueryable<T> relates to sources of data – not instances of the data itself (possible exception: Enumerable.AsQueryable()).

    I suspect your method GetTaskAndTimeLine should simply return TaskTimeLine; and lose a lot of the casts…

    public TaskTimeLine GetTaskAndTimeLine(int taskId)
    {
       TaskTimeLine taskTimeLine = new TaskTimeLine(); // create new main object
       ...[snip]
       return taskTimeLine;
    }
    ...
    TaskTimeLine task = taskRepository.GetTaskAndTimeLine(id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.