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

  • Home
  • SEARCH
  • 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 8562405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:43:23+00:00 2026-06-11T16:43:23+00:00

I have a standard model set. I have a base context class that inherits

  • 0

I have a standard model set.

I have a base context class that inherits from dbcontext to add some features I needed.

public class MyContext : DbContext
{
    public void MyFeature() {
    }
}

I then have my actual Data Context:

public class DataContext : MyContext
{
    public DbSet<Category> Categories { get; set; }
    public DbSet<Product> Products { get; set; }
}

I want to use the scaffolder built in when you create a controller, but I get an error “Unsupported Context Type”
If I change the datacontext to just inherit from dbcontext directly it works, but at this point I have alot of stuff that uses the added features, so changing the inheritance cant be done without commenting out all that stuff. And I have of course simplified down the features, it is actually quite alot of stuff, so adding it directly into the datacontext would be alot of work, plus the scaffolder should be smart enough to see that the datacontext is a dbcontext.

How can I use the scaffolder with my datacontext?

  • 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-11T16:43:24+00:00Added an answer on June 11, 2026 at 4:43 pm

    Why don’t you use Composition?

    If your feature really is just needed as lets say a few methods needed in those objects I would put those methods in a separate class called ContextDetails – something along those lines and have DataContext contain a ContextDetails like so:

    //Changed MyContext to ContextDetails
    public class ContextDetails 
    {
        public void MyFeature() 
        {
            //Do something
        }
    }
    
    public class DataContext : DbContext
    {
        public DbSet<Category> Categories { get; set; }
        public DbSet<Product> Products { get; set; }
    
        public ContextDetails DbDetails { get; set; }
    }
    

    And if the ContextDetails object needs information about the DataContext/DbContext it’s in pass the DataContext/DbContext into a method or even the constructor.

    If you don’t like Composition for this problem maybe you want to use an Interface. If that’s the case check out http://www.codeproject.com/Tips/309753/Repository-Pattern-with-Entity-Framework-4-1-and-C

    The context class must inherit from System.Data.EntityDbContext which provides facilities for querying and working with entity data as objects

    The best reason I could find for why the inheritance is not working in your example.

    EDIT:

    I read my answer and realized DBDetails might not be the best name but you get the idea. Extract the implementation and use it as a separate entity. Good luck!

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

Sidebar

Related Questions

I have a standard ActiveRecord model with the following: class MyModel < ActiveRecord::Base custom_method
I have a standard active record model with an attributes that is required: class
Suppose we have two variables that we wish to build a model from: set.seed(10239)
I have the standard 'RequiredIf' attribute for some Conditional-Validation. My form and Model are
Given that I have a Foo model w/ the standard Rails timestamp columns what
I have a simple model class Ad < ActiveRecord::Base has_many :ad_items end class AdItem
I have a model that has a bone which has a translated offset from
I have a call to a model which is just a standard class (not
I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have some models, connected with GenericForeignKey : Class Main(models.Model) filed_1 = models.CharField(max_length=20) object_id

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.