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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:06:19+00:00 2026-05-24T09:06:19+00:00

Linq and EF. I’m pretty new so I have some problem to retrieve entities

  • 0

Linq and EF.

I’m pretty new so I have some problem to retrieve entities using a Navigational Property (CmsContents).
I can return as an List but not as an IEnumerable.

  • Could you tell me what is wrong in my code?
  • Also do you know a better approach to retrieve Entities suing Navigational Properties?

Please provide me an example of code thanks!

    public IEnumerable<CmsGroupsType> GetMostPopularContents()
    {
        using (var context = new CmsConnectionStringEntityDataModel())
        {
            context.CmsGroupsTypes.MergeOption = MergeOption.NoTracking;
            var contents = context.CmsGroupsTypes.Single(g => g.GroupTypeId == 1).CmsContents;
            return contents.ToList();                                         
        }
    }

Error   1   Cannot implicitly convert type 'System.Collections.Generic.List<WebProject.DataAccess.DatabaseModels.CmsContent>' to 'System.Collections.Generic.IEnumerable<WebProject.DataAccess.DatabaseModels.CmsGroupsType>'. An explicit conversion exists (are you missing a cast?)
  • 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-24T09:06:20+00:00Added an answer on May 24, 2026 at 9:06 am

    The generic types don’t match: Your .ToList() is of CmsContent, but your return type is an IEnumerable of CmsGroupsType. I’m not sure if that was intentional, but changing the return type to IEnumerable<CmsContent> will make everything work.

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

Sidebar

Related Questions

Using LINQ to Entities, how can I determine if any item from a List
Using LINQ to Entities with Entity Framework and C#: I have a method that
Using linq to sql I would like to generate some sealed classes in a
This linq works fine: return (from page in db.WebPages where pageids.Contains(page.page_id) select new Result
Using LINQ I would like to retrieve all files under a given directory that
Using Linq; how can I do the opposite of Take? I.e. instead of getting
Using LINQ in .Net I can select items from an array that match a
In LINQ to SQL, I can create a repository dynamically using DataContext.GetTable<T> . Is
Using LINQ-to-Entities 4.0, is there a correct pattern or construct for safely implementing if
The LINQ code returns a anonymous type how can I return a strong type

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.