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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:11:37+00:00 2026-05-28T15:11:37+00:00

Grabbed this from a sample: protected override ObjectContext CreateDataSource() { NorthwindContext nw = new

  • 0

Grabbed this from a sample:

protected override ObjectContext CreateDataSource()
    {
        NorthwindContext nw = new NorthwindContext();

        // Configure DbContext before we provide it to the 
        // data services runtime.
        nw.Configuration.ValidateOnSaveEnabled = false;

        // Get the underlying ObjectContext for the DbContext.
        var context = ((IObjectContextAdapter)nw).ObjectContext;

        // Return the underlying context.
        return context;
    }       

Modified it to use the DbContext class that I have in my project.

EDIT: Clarifying that I am casting from a DbContext class just as the sample does:

    public class NorthwindContext : DbContext
{
// Use the constructor to target a specific named connection string
public NorthwindContext()
    : base("name=NorthwindEntities")
{
    // Disable proxy creation as this messes up the data service.
    this.Configuration.ProxyCreationEnabled = false;

    // Create Northwind if it doesn't already exist.
    this.Database.CreateIfNotExists();
}

Running the code gives me an error on the line casting the DbContext:

Unable to cast object of type ‘MyProject.MyDbContext’ to type ‘System.Data.Entity.Infrastructure.IObjectContextAdapter’.

Despite the fact that DbContext implements IObjectContextAdapter:

public class DbContext : IDisposable, IObjectContextAdapter

I’ve found several questions here on SO and other googled sources, but no solutions I have found work.

I’m using Entity Framework 4.2, attempted to update to the 4.3 beta and I’m not sure if that stuck.

Overall goal is to serve data in WCF as a DataService.

Update: Digging deeper I find that there is an ambiguity issue between what my DbContext was (From EntityFramework.dll ) and the type in the WCF project (from Microsoft.data.Entity.CTP)

Not sure how to get what I want from both here….

  • 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-28T15:11:38+00:00Added an answer on May 28, 2026 at 3:11 pm

    Just a reminder, the issue here was that an ambiguity between EntityFramework.dll and Microsoft.Data.Entity.CTP was causing the DataInitializer I had for my DbContext to lose functionality.

    I solved this issue by replacing my Initializer here:

    public class MyDataInitializer : RecreateDatabaseIfModelChanges<MyData>
    {
        public void Seed(MyData context)
    

    To:

        public class MyDataInitializer : IDatabaseInitializer<MyData>
    {
        public void InitializeDatabase(MyData context)
    

    And I can now access my DataService.

    Just one

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

Sidebar

Related Questions

I grabbed a database of the zip codes and their langitudes/latitudes, etc from this
I grabbed this compact news reader from here Below is the code for animating
I grabbed this snippet from another question: <script type='text/javascript' > $(document).ready(function () { $(div.content
So my software is displaying a flextable (the data is grabbed and displayed from
Right now I successfully grabbed the full element from an HTML page with this:
I have a delimiter string like this: 2,3 which is grabbed from a listbox
I grabbed this example from apples website This example seems to not run at
I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
I grabbed this code form JCarousel and just trying to understand these lines below.
I need to change what rows are grabbed from the database based upon a

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.