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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:41:49+00:00 2026-05-22T22:41:49+00:00

I have an entity in EF called Registry that I use for throwing all

  • 0

I have an entity in EF called Registry that I use for throwing all kinds of useful stuff in. My typical query looks like this:

db.Registry
   .Where(x => x.Domain == "SomeDomain" && x.Key == "SomeKey")
   .Select(x => x.Value)
   .Single();

where db is a variable of type EFContainer. Rather than having this sort of query all over the place I’d like to write something much simpler, perhaps like:

Registry.Get(Key: "SomeKey", Domain: "SomeDomain")

but the problem is that in order for that method to access the database it needs to instantiate EFContainer and when it does, I start to have errors that IEntity change tracker cannot handle the second connection. I suppose I could pass in my db variable to the method but that’s eeky.

What’s a good way to accomplish this?

  • 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-22T22:41:50+00:00Added an answer on May 22, 2026 at 10:41 pm

    The typical way to do this would be to create a RegisterRepository and inject either the EFContainer into the constructor of the repository or inject a mechanism for creating containers.

    public class RegistryRepository {
    public RegistryRepository(EFContainer db) {
      this.db = db;
    }
    
    readonly EFContainer db;
    
    public Registry Get(string domain, string key) {
    // implementation here
    }
    
    }
    

    In this implementation you have to consider how you will obtain a reference to the repository and thus how the repository will be constructed. You may use a dependency injection framework to register the EF container and the repository with a proper lifetime scope. If for example you are developing an ASP.NET application, an EF context would be scoped by an HTTP request as would the repository.

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

Sidebar

Related Questions

If I have an entity called Foo that looks a little like this: @Entity
I have an entity called 'SyncInfo' (including a UUID and a modified date) that
I have a simple entity called Store built in Xcode's data modeler for use
I have a core data entity called images that has just 2 fields: imageName
I have a simple base entity type called EntityBase that implements IEquatable<EntityBase>. I've used
I have an entity that maps to an external oracle table which is one
I have an entity class that has a property with an underlying db column
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I have an entity called Requests which has a navigation called StatusHistories I need
I have an entity called Pupil, and an entity called Loan. The Pupil entity

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.