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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:34:47+00:00 2026-05-27T14:34:47+00:00

I am working with EntityFramework and the IRepository Pattern and I need to add

  • 0

I am working with EntityFramework and the IRepository Pattern and I need to add some events to all EntityCollections.

Is there a way to get a list of collections on an ObjectContext?
I also need a way to get all the collections on an ObjectSet/EntityCollection. Is that possible?

My end goal here to iterate all collections and sub-collections and add an AssociationChanged Event to all my sub-collections. It will call delete on an object when the relationship is deleted.

This to make up for the fact that EF does not support connectionless deletes (at least not like it supports connectionless Updates and Inserts).

  • 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-27T14:34:47+00:00Added an answer on May 27, 2026 at 2:34 pm

    You can get the ObjectSets using the following untested code:

    var objSetProps = instanceOfObjectContext.GetType().GetProperties().Where(prop => prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(ObjectSet<>));
    
    foreach(PropertyInfo objSetProp in objSetProps)
    {
        var objSet = objSetProp.GetValue(instanceOfObjectContext, BindingFlags.GetProperty, null, null, null);
    }
    

    The trick is going to be working with the ObjectSet once you have the instance because it ObjectSet is generic and working with variables of generic types can be less then obvious when you don’t know what type was used to define them.

    As for getting the entity collections on an object set, a similar approach can be taken, but I don’t have an example of doing so on hand at the moment.

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

Sidebar

Related Questions

Can someone tell me how can I get MS Entity Framework working with PostgreSQL.
Working on a project that parses a log of events, and then updates a
I'm working with a new Entity Framework repository and need System.data.entity.design.dll for using the
Is there someone who can please explain why the following is not working??: the
I'm working on an invoicing system using C#, MySql and the EntityFramework. The problem
I need some help with MVC architecture. I use the following architecture for an
We are working with entity framework 4.1 - code first. We need to be
I am working with Entity Framework for a while but still have some black
I'm using the EntityFramework and working on an invoicing application. Below is the xaml
I am working with Entity Framework 4.0 (VS 2010 Beta 2, NOT RC). I

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.