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

安稳与你 提交于 2019-12-06 01:34:47

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.)

Janaka Priyadarshana

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!