ASP.NET MVC (NetCore 2.0) Generic Controller and Views for Handling Entity Frameworks DbContexts and Objects
DRANK

IntroductionThis article and source code has been updated to NetCore 2.0 ASP.NET MVC project.When we start the development of an ASP.NET MVC website in Microsoft Visual Studio, we find it very easy to create controllers and views for each "table" in our databases by using an Entity Framework DbContextand Visual Studio Tools for self-generate code. However, when your database(s) contains many tables, this operation becomes tedious even to generate one controller by one.BackgroundThe Basic RulesFor using the code of this article without modifications, you should follow these rules:Use Code FirstMake sure that in your database design, all entities derive from a Base class.All entities must be flagged with a DisplayTableName attribute.The properties not to be shown at Index views must be flagged as [NotListed]All entities must override ToString() method.The ForeignKey attribute must be set to the ForeignKey property, mapping the naviagation property.NET ReflectionThis technology allow us …

codeproject.com
Related Topics: Windows Visual Studio HTML5