dotnet aspnet-codegenerator view testview edit --model MyModel
returns:
Please provide a valid dataContext
Why scaffolding an Edit
(or any template for that matter) of a View needs to know anything about the dataContext?
Looks like a bug to me.
It would be great to use this for BindingModels and ViewModels...
/cc @prafullbhosale
@Bartmax Right now scaffolding retrieves the model's metadata using the dataContext.
I will sync up with EF guys to see if there is a way to get that without using the dataContext.
/cc @sayedihashimi
@prafullbhosale actually I think this is a mistake. Because the recommendation is to NOT use EF models directly in views/controller stuff (https://github.com/aspnet/Mvc/issues/4666#issuecomment-220156872), so scaffolding something that not only is not recommended, but also dangerous, makes this whole tool for demo only purposes and have little to no value and draw a straight line to failure for new comers.
The metadata is already on the class, no need for a dbcontext, also controllers shouldn't be created based on EF entities passed as action parameters in humble opinion. I hope this metadata can be retrieved from something else but EF.
Scaffolding with a placeholder like:
// insert your logic here
instead of db.SaveChanges()
would be way more useful!
I will be happy to help on these templates if there is interest.
note: this also applies to right click vs -> add controller/view of course.
Totally agree. Ideally this should create
Services \ [ControllerName]Service.cs (hook EF stuff here)
then inject that service into the generated Controller class.
At least that would follow some kind of acceptable pattern.
TFS: 224858
I've added this to our internal TFS, we will reply back here soon.
Most helpful comment
@prafullbhosale actually I think this is a mistake. Because the recommendation is to NOT use EF models directly in views/controller stuff (https://github.com/aspnet/Mvc/issues/4666#issuecomment-220156872), so scaffolding something that not only is not recommended, but also dangerous, makes this whole tool for demo only purposes and have little to no value and draw a straight line to failure for new comers.
The metadata is already on the class, no need for a dbcontext, also controllers shouldn't be created based on EF entities passed as action parameters in humble opinion. I hope this metadata can be retrieved from something else but EF.
Scaffolding with a placeholder like:
instead of
db.SaveChanges()
would be way more useful!I will be happy to help on these templates if there is interest.
note: this also applies to right click vs -> add controller/view of course.