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

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.

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 to enable code-first migrations

There are many examples out there including this.
The problem is that many of the commands are changed, different, or not included with Entity Frameworks.
Can someone tell me how to enable code-first migrations with my project?
I am using visual studio 2015 and the latest version of MVC. My project works on the first build, but then after I kill the app and add another model, I get an invalid column name or suggestion to enable code first migrations.

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

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.

Difference between EF.SqlServer and EF.SqlServerCompact

I want to install Entity Framework in my ASP.NET 5 MVC project using project.json.
In the dependencies section I start typing EntityFramework and I only see
"EntityFramework.SqlServerCompact": "6.1.3" instead of "EntityFramework.SqlServer": "6.1.3".
What is the reason for this and what effects will this have?
Are there limitations in the compact version?
If I create a new ASP.NET 4 project with MVC and install EntityFramework then I see the EntityFramework.SqlServer reference installed and not the compact.
EntityFramework.SqlServerCompact is for interacting with SQL CE. It's a single file based database. If you're dealing with MS SQL Server, that's definitely not what you want. You want EntityFramwork 6.1.3, there is no EntityFramework.SqlServer.

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.

Resources