Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:'Unsupported context type' while creating a new controller

I am going to implement MvcMusicStore using ASP.NET MVC3, Linq to Sql class instead of Entity Framework, MS SQL Server 2008 pro instead of express ed.

I got the tutorial from mvcmusicstore.codeplex.com

I used Linq to Sql class and the Datacontext is MvcMusicSrotedataContext. When i try to create a new class using this

image

it shows an error in a new window when i click add button Error:'Unsupported context Type'

So, could you please help me to solve this? Thank You.

like image 808
arefinsami Avatar asked Jul 11 '26 19:07

arefinsami


2 Answers

The built-in MVC scaffolding doesn't support Linq to SQL -- you'll have to use Entity Framework instead. (Or don't use the scaffolding, build your own controller/action logic manually. Or use a scaffolding plugin that supports Linq to SQL.)

like image 65
McGarnagle Avatar answered Jul 16 '26 02:07

McGarnagle


I got the same issue with EF. I am using the VS 2012.

Background:

The reason for my case was.. this auto generation process (Scaffolding) seems not recognize the partial class concept.

I used the model first approach and I have used inheritance with the entities. Ex: entity “B” and “C” is inherited from “A”

So in my generated model class “DataModelContainer” which is inherited from “DbContext”, There is no definition for “DbSet” and “DbSet” i.e: the following two lines were not there

public DbSet<B> B { get; set; }
public DbSet<C> C { get; set; }

Generated “DataModelContainer” class I a partial class, so I completed the other part, using the concept of partial class. And this would be a problem for Scaffolding.

Solution

My workaround was, just removed the partial class I added manually. And added the definitions for “DbSet” and “DbSet” in to the auto generated class. The problem with this solution is, I have to repeat the same thing when I regenerate the model classes.

like image 42
Janaka Priyadarshana Avatar answered Jul 16 '26 02:07

Janaka Priyadarshana