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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:43:34+00:00 2026-06-18T11:43:34+00:00

I am using Entity Framework 5 with Code First approach and using Fluent API

  • 0

I am using Entity Framework 5 with Code First approach and using Fluent API for Entity configuration. My project has one particular Product Entity which gets half of its data from the database and the other half from a Data Contract retrieved via a WCF Client (its a 3rd party system used to manage product inventory). The Data Contract is a member of the Product Entity class (property or method I haven’t decided yet).

I prefer not to have any WCF Client logic contain within the Entities. I’d prefer to keep this logic in Repository code (DbContext, DbSet, etc.).

So is there a technique to hook into Entity Framework (or intercept) just after a Product Entity is retrieved from the database? I should note the Product Entity appears as a navigation property on other Entities. If a hook or intercept is possible then what that means is I can retrieve the Data Contract from the SOAP service immediately after EF loaded the Product Entity from the database. The benefit for my project is the WCF Client retrieval code does not need to be repeated throughout the application.

One idea I had was to implement IDbSet for the Data Contract and the IDbSet would be responsible for retrieving it. And then somehow trick EF into thinking its a navigation property on the Product Entity. But I wasn’t sure if a database DbSet can be mixed with a non-database IDbSet all within the same DbContext. And also the other question – how would EF know to retrieve a navigation property from the IDbSet implantation? I’d prefer to know if this idea is possible before investing time into it. I’d also prefer to know where to start looking.

Please note I’ve been working with .NET for over 10 years but this EF5 stuff is still relatively new to me.

Thanks in advance.

-Sam

  • 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-06-18T11:43:35+00:00Added an answer on June 18, 2026 at 11:43 am

    Today I found an event in the Entity Framework that seems to be what I am looking for. ObjectContext.ObjectMaterialized Event. Apparently, DbContext implements IObjectContextAdapter which in-turn exposes the ObjectContext. From there I can subscribe to the ObjectMaterialized event.

    MSDN Reads:
    Occurs when a new entity object is created from data in the data
    source as part of a query or load operation.

    The following code demonstrates how I used the ObjectMaterialized event to solve my problem in which one of my preferences was to have a central point to place the WCF client access logic.

    // seperate assembly - does not use Domain.Repositories assembly
    namespace Domain.Models
    {
        // the data contract
        [DataContract]
        public class ProductInventoryState
        {
            [DataMember]
            public int StockStatus { get; set; }
    
            [DataMember]
            public IEnumerable<String> SerialNumbers { get; set; }
    
            // etc....
        }
    
        // the entity
        public class Product
        {
            public Guid Key { get; set; }
            public string ProductCode { get; set; }
            public ProductInventoryState InventoryState { get; set; }
            // etc....
        }
    }
    
    // seperate assembly - uses Domain.Models assembly
    namespace Domain.Repositories
    {
        public class MainRepository : DbContext
        {
            public MainRepository()
            {
                ((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized += ObjectContext_ObjectMaterialized;
            }
    
            protected void ObjectContext_ObjectMaterialized(object sender, ObjectMaterializedEventArgs e)
            {
                if (e.Entity == null)
                    return;
    
                if (e.Entity is Product)
                {
                    Product product = (Product)e.Entity;
    
                    // retrieve ProductInventoryState from 3rd party SOAP API
                    using (ThirdPartyInventorySystemClient client = new ThirdPartyInventorySystemClient())
                    {
                        // use ProductCode to retrieve the data contract
                        product.InventoryState = client.GetInventoryState(product.ProductCode);
                    }
                }
            }    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Entity Framework 5, and a code first approach. I have a Product
I'm trying to map an existing database using Entity Framework Code First Fluent API.
I am creating a new database model using Entity Framework 4.3 Code-FIrst; using Fluent
I am successfully creating database (SQL Ce) using Entity Framework Code First approach (C#-WPF).
I am trying to update my entity using Entity Framework 4.1 code First approach
I am using the latest Entity Framework with a code-first approach to create a
I'm using ASP.NET MVC 3 with the Entity Framework 4 code first approach and
I'm building an ASP.NET MVC 3 site using the code-first Entity Framework 4 approach.
I have the following table created using Entity Framework Code First approach. How do
I'm using Entity Framework 4 Code First in my .net MVC 2.0 project and

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.