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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:26:16+00:00 2026-06-05T15:26:16+00:00

Is there anyway to create an ObjectSet from a DbSet ? Some background information:

  • 0

Is there anyway to create an ObjectSet from a DbSet?

Some background information: I have a model (EF 4.2) that is returning DbSets within the object context. I need to retrofit it to support an API from an older data model (EF4). The older data model was returning object sets, and several methods within the API (an IIS hosted WCF 3.5 Service) accept query string predicates that were passed to the older model. I need to replicate this behavior in the new model, however, the DbSet.Where method does not accept a string predicate parameter. I was able to get it to work partially by creating an object set from the Object Context (ObjectContext.CreateObjectSet<T>(string)) however doing it this way I can’t seem to get any include statements to work correctly.

Is there a way to either pass string predicates into a DbSet, or is there a way to get an ObjectSet from a DbSet in which the .Include method loads the related data sets?

Thanks in advnce (some code snippets below):

Class to create ObjectSet (so I initialize with my context and instead of using the DbSet returned for these in ClinicalContext.Exams etc, I get the underlying Object Context and create an EntitySet from that using the same objects that would be contained in the DbSet.

public class ExamServicesEntities
{
    private ClinicalContext _Context;
    public ExamServicesEntities(ClinicalContext context)
    {
        _Context = context;
    }

    private ObjectSet<Exam> _ExamEntities;
    public ObjectSet<Exam> Exams
    {
        get
        {
            if (_ExamEntities == null)
            {
                _ExamEntities = _Context.ObjectContext.CreateObjectSet<Exam>("Exams");
            }
            return _ExamEntities;
        }
    }

    private ObjectSet<Visit> _VisitEntities;
    public ObjectSet<Visit> Visits
    {
        get
        {
            if (_VisitEntities == null)
            {
                _VisitEntities = _Context.ObjectContext.CreateObjectSet<Visit>("Visits");
            }
            return _VisitEntities;
        }
    }

}

Doing this loads the data correctly but when I attempt to Include one of the other objects (Exam contains a Visit, Visit contains a Patient) the references are not built.

  • 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-05T15:26:17+00:00Added an answer on June 5, 2026 at 3:26 pm

    Solved this by copying and tweaking the T4 template used to generate the context object to generate a second context onject based on ObjectSet.

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

Sidebar

Related Questions

Is there anyway to create a dialog that is modal to a view and
Is there anyway to create a desktop icon (cross platform/browser) from a linked image
Is there anyway to create C# spelling checker without using Office library? I would
Is there anyway I can create nodes out of a string? I've searched the
Is there any way to create a new NSString from a format string like
Is there anyway to get $self into a MooseX::Types coercion? I have other data
In rails 3, I have a database model that has a birthday field, of
I have a RemoteFile that inherits from Pathname class RemoteFile < Pathname end I
I have some model classes like Customer , Product , etc. in my project
Is there any way to create a dynamic Pinterest button? I'm trying to add

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.