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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:12:20+00:00 2026-05-26T19:12:20+00:00

I am trying to create a list of POCOs from my database. The POCO

  • 0

I am trying to create a list of POCOs from my database. The POCO class has a List<int> property which I want to populate like so:

public List<Pocos.MyTable> GetData()
{
    using (EFContext c = new EFContext())
    {
        var query = from t in c.MyTable
                    select new Pocos.MyTable()
                    {
                        MyId = t.MyId,
                        MyField = t.MyField,
                        MyRelationIds = t.MyRelations.Select(mr => mr.MyRelationId).ToList()
                    };

        return query.ToList();
    }
}

Unfortunately I am getting the “this method cannot be translated into a store expression” on the ToList()in the query. Can I do this nicely here, or do I have to do lots of subsequent queries to populate the MyRelationIds property?

  • 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-26T19:12:20+00:00Added an answer on May 26, 2026 at 7:12 pm

    From your code and description I got, that if try to just use MyRelations, it is not loaded. And then you try to populeta MyRelationsIds during query. There are two ways to solve this. I personally prefer the first one:

    1. Replace your MyRelations property with public virtual List<Relation> MyRelations. Virtual is a convention, after which EF will create a proxy, that will act as a lazy property. I.e. it will be loaded as soon as you touch it.
    2. Another way is to use eager loading, with it you don’t have to change the signature.
      Just use Include method, to tell EF which props do you want to load eagerly.
      See that .Include("MyRelations") it tell, that MyRelations must be loaded during this query. So you can use them later. And if you want to have only ids of relations, then you should first materialize your objects and then do mapping (note AsEnumerable())

      using (EFContext c = new EFContext())
      {
          var query = from t in c.MyTable.Include("MyRelations").AsEnumerable()
          select new Pocos.MyTable()
          {
              MyId = t.MyId,
              MyField = t.MyField,
              MyRelationIds = t.MyRelations.Select(mr => mr.MyRelationId).ToList()
          };
      
          return query.ToList();
       }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to create a list of the items from my database. the problem
I'm trying to create a list of a class that has nested class in
I'm trying to create a list that has a header, just like a JTable,
I'm trying to create a list fragment activity like this : public class FluxListeFragment
I am trying to create a list where I want users to enter data
I'm trying to create a list of tasks that I've read from some text
I am trying to create a list of a certain type. I want to
I am trying to create a list view which as TextView that can display
I'm trying to create a list adapter that pulls in and displays data from
Im trying to create a list of strings using some recursion. Basically i want

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.