Is there a reason the built in MVC View Scaffolding in Visual Studio 2015 does not work with inherited base classes that contain a generic id? 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; }
}
Trying to create a scaffolded view (e.g. List, Create, Edit, Delete) using the Country entity results in the following error pop-up:
There was an error running the selected code generator: 'The method or operation is not implemented.'
If I remove the TKey
type parameter and make Entity
non-generic by defining a fixed type for Id, I can then scaffold the views.
I know in this simple case, I'm not saving myself much work by having the generic base class. I'm also aware that the "best practice" is to use View Models instead of Domain Models in your views. However, I'd like to understand why using a base class with a generic type is causing an issue with the scaffolding.
I also experienced that bug and found out it was already reported on Microsoft Connect. The only options we seem to have for now are:
Note: It seems the same problem affects Visual Studio 2013 (Update 5) but I didn't find any bug tracker entry for that.
Should you want to follow the advancement of the bug fix or provide further information to the support team, you can pay a visit to Microsoft's bug tracker here: https://connect.microsoft.com/VisualStudio/feedback/details/2187798/mvc-view-scaffolding-not-working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With