David Silva-Barrera
David Silva-Barrera

Reputation: 1136

.Net Entity Framework scaffolding for inherited classes

I'm working visual studio 2010, mvc 4. I'm applying a model first approach and I have a hierarchy of some classes. VS scaffolding works well with all other classes even base class for hierarchy, but child classes don't get scaffolding working. I see and understand that only base class goes to my dbcontext implementation, and I'm starting to be afraid of the null possibility of using directly scaffolding with child classes. Am I missing something or should I stop searching and begin to make them manually?

Upvotes: 1

Views: 252

Answers (1)

David Silva-Barrera
David Silva-Barrera

Reputation: 1136

By now I found and insteresting solution but I'm still looking for something less tricky. Let's me explain: EDMX only adds base class to ModelContainer: public DbSet Personas { get; set; } With it its possible to very well read/write data from/to database through context.Personas.Add() ... But scaffolding looks for a DB when I try to make controller/views for the ChildClass model and it's not there. My tricky solution: make another partial class ModelContainer and add those DbSet there. Remember that the original is autogenerated and can't be manually edited permanently... uhmmm... Better, you can add it to the original ModeloContainer, compile and then use scaffolding. It'll work ok and it's no longer needed so no problem if you regenerated the Container class again from the EDMX.

But please, if anyone know a better or correct way, point it here.

Upvotes: 1

Related Questions