How to create custom scaffold templates which are not using entity framework entities directly in ASP.NET MVC5? - asp.net

I'm using VS 2015 with EF 6.1.3. with MVC5.
I know that MVC5 scaffolding templates are located in
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\
But I cant use them since standard scaffolding is not an option for me.
I would like to generate similar views and controllers against my custom POCO classes eg. ViewModels that are located in BL.
Can you run and customize those (or some other) templates so that they could generate MVC controllers and views from some other classes or repository?

Here's a good general article for custom scaffold templates in MVC
https://www.credera.com
http://www.c-sharpcorner.com
https://www.youtube.com/watch?v=YIr18d5wBXM
May be it's helpful for you.

If you are already use to T4 template syntax you can try out my extension T4 Awesome. It adds a lot of UI to visual studio for running templates and supports parameters, one of which is a code type that allows you to use POCO class metadata inside your templates. This would allow you to generate views and controller stubs much like scaffolding does but in a very quick way. In scaffolding you have to build/test/compile/deploy your scaffolds, its almost like working on another project altogether. With T4 Awesome, all you do is create your templates and use them, edit as needed, and this all happens within the same solution as your code. Full disclaimer, there is a charge for using the advanced features but I do have a community edition that will do what you want and is free for forever.

Related

Upgrading .NET Framework 4.5 to 4.6.1 causes errors in Entity Framework classes

IDE :: VS.NET 2015
Version Upgrade :: 4.5 To 4.6.1
My asp.net solution contains more than 30 projects inside. I have upgraded the targeted framework to 4.6.1 and now i am getting these tons of error in EF classes. The existing EF version is 6.0.
Please suggest how to fix these errors cropped up from the EF classes. Should i upgrade the EF version also from the Nuget console also.
If you have any models created with the EF Designer, you will need to update the code generation templates to generate EF6 compatible code.
Delete existing code-generation templates. These files will typically be named .tt and .Context.tt and be nested under your edmx file in Solution Explorer. You can select the templates in Solution Explorer and press the Del key to delete them.
Note: In Web Site projects the templates will not be nested under your edmx file, but listed alongside it in Solution Explorer.
Note: In VB.NET projects you will need to enable 'Show All Files' to be able to see the nested template files.
Add the appropriate EF 6.x code generation template. Open your model in the EF Designer, right-click on the design surface and select Add Code Generation Item...
If you are using the DbContext API (recommended) then EF 6.x DbContext Generator will be available under the Data tab.
Note: If you are using Visual Studio 2012, you will need to install the EF 6 Tools to have this template. See Get Entity Framework for details.
If you are using the ObjectContext API then you will need to select the Online tab and search for EF 6.x EntityObject Generator.
If you applied any customizations to the code generation templates you will need to re-apply them to the updated templates.

How do I tell if Razor is enabled in my existing MVC project?

I have an existing ASP.NET project updated from VS2010 to VS2015. It had some MVC portions that I would like to expand on, and would like to take advantage of Razor. How can I tell if that is available or can it be enabled if it is not? Can I mix Razor with non-Razor MVC?
Thank you for your help!
Razor uses the library 'System.Web.WebPages.Razor'; you'll need to make sure your project includes a reference to this library. You can also check that the nuget package is installed by going to Tools -> Package Manager -> Manage Nuget Packages For Solution:
Can I mix Razor with non-Razor MVC?
If you're using MVC, the views you create will be .cshtml (assuming C#) and will support the Razor syntax by default. You can also use traditional HTML, JavaScript, JQuery, etc in these .cshtml pages. I'd have a look at Microsoft's Razor syntax doc:
Razor Syntax Reference
I'm almost sure Razor comes by default with VS2015, just open an .cshtml file and try to write with Razor syntax.
#("Hello World!")

how do i switch my repositories so that i can use code First EF approch instead Model First Edmx Approch

In Existing project implementation done from edmx model first approach EF I have to use Code First approach . In existing project developed creating repository BO ,base Bo ,Enum classes . Have to reflect the same with just change in approach.
You can use the EntityFramework Reverse POCO Generator Visual Studio extension. As its documentation says:
Reverse engineers an existing database and generates EntityFramework Code First POCO classes, Configuration mappings and DbContext.
Also, you can use the Entity Framework Power Tools Visual Studio extension, which includes more functionalities, like generating diagrams of your data models.
To use EF PowerTools with Visual Studio 2015 do as explained in this post.
In addition to generate your POCO entities and database context you will have to enable the use of migrations with the Package Manager Console and to generate at least an initial migration for your database. You will get a migration Configuration class, and will need to configure a Database Initializer. This page explains the basics of these steps.

ADO.NET Entity Data Model missing Visual Studio 2015 community

I am starting a new ASP.NET 5 Preview template to play with client side development.
I have a database ( MS SQL ) that I want to access using the Web API and Entity Framework.
In my Models folder I do like I am used to do, add a new item and I want to add the ADO.NET Entity Data Model but it isn't there.
What am I missing here?
UPDATE
This is the only thing I see when I try to add a new item to the project.
Client side and server side.
After a lot of research, I found out that there are some compatibility issues where come from the recent Microsoft migration to open source world (since Asp.net5) that I obtained from Data Points - The EF6, EF7 and ASP.NET 5 Soup MSDN Article. Read the full article please.
So if you wanna have both EF6 and Asp.net5, consider the article tips. And if you don't persist in using Asp.net5, simply use Asp.net4.5 (following image) which have Ado.net Data Model in Add New Item dialog (I tested its availability with my Visual Studio Enterprise).
May sound stupid, but since I got caught with this, it might be someone else's issue too...
In VS 2015, there are 2 project templates called Class Library... one being in Windows and one in the Web and having (package) suffix. Apparently, besides misleading name they have nothing to do with each other and the second one clearly is not made to support EF models... Make sure you have created a proper project type or open a working solution made with different VS version.
__
Also this might help. I have it already installed, so not sure if it affects my configuration or not (shouldnt as EF tools are supposed to be shipped already with VS 2015):
http://thedatafarm.com/data-access/installing-ef-power-tools-into-vs2015/
Right click on project
Choose Add and then New Item (or Simply press Ctrl+Shift+A)
You will see a Data section which you can find what you are looking for
Or You can find another solution Here:
Missing ADO.NET entity data model template from visual studio 2012 professional
Create New MVC Project using VS2015
Right-Click on Model folder.
Choose Add and then Select Class from the list.
Now select ADO.Net Entity Data Model... and go for your selection.
ADO.NET Entity Data Model missing Visual Studio 2017 Community
How to enable:
Open Visual Studio Installer -> Individual Components -> SDK's, libraries, and frameworks -> Enable EntityFramework 6 tools-> Modify
Now, Add item in your project -> Data -> ADO.NET Entity Data Model.
Visual Studio Installer
Note: While Creating project don't select class Library(.NET Standard) Choose Class Library (.NET Framework)
I solved the same problem by following these:
While Creating project don't select class Library(.NET Standard)
Choose Class Library (.NET Framework)
Choose ASP.NET Web Application (.NET Framework)
Go to Tools -> Get Tools and features. Select Individual components tab and check Entity Framework 6 tools under SDK's, libraries, and framework section
Remember you can't make an ADO.net Entity Data Model with an interface with .NET Core, its only possible with .NET Framework.

What is the purpose of Antlr package in Visual Studio 2013 ASP.NET project?

The ASP.NET (web forms) project template in Visual Studio 2013 includes several packages. I'm trying to figure out which ones are essential (may need to create a separate question for this). The post at http://blogs.msdn.com/b/webdev/archive/2013/10/16/asp-net-features-in-new-project-templates-in-visual-studio-2013.aspx explains the purpose of some of them, but I cannot figure out which need Antlr serves. Can someone clarify?
It is a transitive dependency declared in the WebGrease package, where it is used for a CSS lexer and parser.
Also relevant for Visual Studio 2015 (ASP.NET MVC 5)
Bundling and minification in the ASP.Net templates is implemented in Microsoft.AspNet.Web.Optimization, which depends upon WebGrease, which itself depends upon Antlr.
So if you want to take advantage of ASP.Net template's built-in bundling and minification, you need them all.

Resources