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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:27:09+00:00 2026-05-31T17:27:09+00:00

First I will explain what I am trying to do. I am trying to

  • 0

First I will explain what I am trying to do.

I am trying to grab a list of news articles from my entity framework and convert them to another object. However I get this exception:

System.NotSupportedException: LINQ to Entities does not recognize the method 'Database.Entity.DataTransferObjects.NewsObject FromNews(Database.Entity.News)' method, and this method cannot be translated into a store expression.

This is my code:

IEnumerable<NewsObject> news_articles = context.GetLatestNews(0);

    public IEnumerable<NewsObject> GetLatestNews(int start)
    {
        IQueryable<NewsObject> latest_news = context.News.Where(news => news.Published).Select(articles => NewsObject.FromNews(articles));
        IEnumerable<NewsObject> latest_news_ordered = latest_news.OrderByDescending(news => news.PublishedDate).Skip(start).Take(5);
        return latest_news_ordered;
    }

This is my FromNews part:

    public static NewsObject FromNews(News news)
    {
        return new NewsObject
        {
            Id = news.Id,
            Permalink = news.Permalink,
            Subject = news.Subject,
            Summary = news.Summary,
            Content = news.Content,
            Thumbnail = news.Thumbnail,
            Published = news.Published,
            PublishedDate = news.PublishedDate,
            PublishedBy = news.PublishedBy,
            CategoryId = news.CategoryId,
            Publisher = MemberObject.FromMember(news.Publisher),
            Category = CategoryObject.FromCategory(news.Category)
        };
    }

I read it’s a problem with the way LINQ is built/used but none of them provided a work around for what I am doing. I am trying to make code tiday :)!

  • 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-31T17:27:11+00:00Added an answer on May 31, 2026 at 5:27 pm

    It should work if you do it this way:

    public IEnumerable<NewsObject> GetLatestNews(int start)
    {
        IQueryable<NewsObject> latest_news = context.News
            .Where(news => news.Published)
            .ToList()
            .Select(articles => NewsObject.FromNews(articles));
        IEnumerable<NewsObject> latest_news_ordered = latest_news
            .OrderByDescending(news => news.PublishedDate)
            .Skip(start).Take(5)
            .AsEnumerable();
        return latest_news_ordered;
    }
    

    By invoking ToList() on your query, EF hits the db and no longer builds expression trees into your iqueryable. After the query is executed, it will pass to your FromNews method.

    Update

    To address the Skip and Take excerpts from comments, something like this could be done:

    public IEnumerable<NewsObject> GetLatestNews(int start)
    {
        IQueryable<NewsObject> latest_news = context.News
            .Where(news => news.Published)
            .OrderByDescending(news => news.PublishedDate)
            .Skip(start)
            .Take(5)
            .ToList()
            .Select(articles => NewsObject.FromNews(articles))
            .ToList(); // see Daniel Hilgarth's answer also
        IEnumerable<NewsObject> latest_news_ordered = latest_news
            .AsEnumerable();
        return latest_news_ordered;
    }
    

    Reply to comments

    Sorry I didn’t realize you were converting from IQueryable to IEnumerable. You can do this by calling the .AsEnumerable() method on the IQueryable instance. I have updated the code posted.

    I have also updated the code to invoke .Skip and .Take before .OrderByDescending. This makes sense because if you skip and take before ordering, your results will only be ordered within the 5 records you take. You need to order, then skip and take.

    Also see Daniel Hilgarth’s answer regarding deferred execution on the .Select method.

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

Sidebar

Related Questions

Okay, first off I will attempt to explain what I'm trying to do. I
I will first explain what I'm trying to do then I will explain why
First I will try to explain what I want to do. The app loads
First I'm going to explain what I'm trying to do, before asking the question
First of all to explain what I'm trying to do: void Foo(int &num, bool
First of all, I should explain what I'm trying to do first. I'm creating
I am basically trying to create a display object transformation manager which will allow
I will try to explain as well as possible what I'm trying to do.
First, I'll explain the situation and the logic that I'm trying to implement: I
To explain what I'm trying to do: I have a navigationController with a list

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.