MVC View Scaffolding not working with a base base class?

Is there a reason why the built-in MVC View Scaffolding in Visual Studio 2015 does not work with legacy base classes that contain a common identifier? A simple test case:

public abstract class BaseEntity { } public abstract class Entity<TKey> : BaseEntity { public TKey Id { get; set; } } public class Country : Entity<int> { public string Name { get; set; } public string CountryCode { get; set; } } 

An attempt to create a view in the form of forests (for example, "List", "Create", "Edit", "Delete") using the "Country" object will result in the following error pop-up window:

An error occurred while starting the code generator: "Method or operation not implemented."

If I remove a parameter of type TKey and make Entity non-generic by defining a fixed type for Id, I can then raise the views.

I know in this simple case, I do not save a lot of work, having a common base class. I also know that the โ€œbest practiceโ€ is to use view models instead of domain models in your views. However, I would like to understand why using a base class with a common type causes a problem with scaffolding.

+5
source share
1 answer

I also experienced this error and found out that this was already reported in Microsoft Connect. The only options we have now are:

  • Generating views from the controller by temporarily removing inheritance (but this is not a great idea, but can avoid wasting time)
  • Microsoft Pending Fix

Note It seems that the same problem affects Visual Studio 2013 (update 5), but I did not find an entry for it to track errors.

If you want to monitor the improvement of error correction or provide additional information to the support team, you can visit our Microsoft error tracker here: https://connect.microsoft.com/VisualStudio/feedback/details/2187798/mvc-view-scaffolding-not -working

+2
source

Source: https://habr.com/ru/post/1237255/


All Articles