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

  • Home
  • SEARCH
  • 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 7404537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:16:09+00:00 2026-05-29T05:16:09+00:00

I know in entity framework you are able to do something like public MyObject

  • 0

I know in entity framework you are able to do something like

public MyObject myObj {get;set;}
public int myObjId {get;set;}

which provides me access to either the key or the corresponding object. However, can you do something like for 1.M associations?

public ICollection<MyObject> myObj {get;set;}
public ICollection<int> myObjIds {get;set;}

Would be very useful if you can.

  • 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-29T05:16:10+00:00Added an answer on May 29, 2026 at 5:16 am

    No, you can’t. At least not in the sense that EF would automatically populate the key collection for you when you load the object from memory (as it is the case with foreign key properties).

    But you have two alternative options:

    You can create a readonly property:

    public ICollection<MyObject> myObj {get;set;}
    public IEnumerable<int> myObjIds
    {
        get { return myObj.Select(o => o.Id); }
    }
    

    This requires that you either have already loaded the myObj collection or that you use lazy loading.

    The second way is to load the Ids explicitely when you need them:

    IEnumerable<int> myObjIds = context.Parents
        .Where(p => p.Id == 1)
        .Select(p => p.myObj.Select(o => o.Id))
        .Single();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You know firstly Entity Framework came with Visual Studio 2008 SP1. Now it is
Anyone know how to query for a specific date within entity framework ? I
Does anyone know of any good tutorials on ADO.NET Entity Framework? There are a
Does anyone know if there is a framework out there that is able to
I know that Entity Framework supports Partial trust, I personally blogged about that It
I know that the geography sql type isn't supported in the entity framework. It
I know that Entity Framework has some LINQ support problems (at least in comparison
Entity Framework 4.0 wasn't able to create auto-incremented integer identity keys with SQL Compact
We're using Entity Framework 4.0. When we encounter a problem in production, we'd like
My problem is that when I get a SQL exception from the entity framework

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.