How to apply Entity Framework code first approach to a project - entity-framework

I use Visual Studio 2013 and need to use Entity Framework code first approach in a project. I used NuGet Manager to install EF v6.1 into my project. But I can't create an empty code first model or even a code first model from database although there are two other choices (DB first and Model first).
How I can add Entity Framework code first feature to my project?

Here is a beginners tutorial for using entity framework code first:
An Absolute Beginner's Tutorial for understanding Entity Framework's Code First Approach in ASP.NET MVC

Related

Convert EDMX to Code first to upgrade from.net framework 4.6 to .net Core 2.0

I need to upgrade my existing .net framework project to .net core 2.0.
I have noticed that .NET Core 2.0 doesn't have support for EDMX (Entity Framework). Do I need to convert EDMX to Code First approach and then upgrade to .NET Core?
What is the easiest and quickest way to do that?
Will EF 5.x DbContext Fluent Generator for C# help to convert EDMX to Code First?
You do not convert EDMX to Code First. What you need to do is reversed engineering by Scaffold-DbContext command, based on the existing database. You can completely remove the EDMX, current context and model classes and let EF Core scaffold new classes. From that point on, you work in Code First mode (make changes to model classes and create migrations, etc). Please see this link for instruction how to do it:
https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx

Can't configure Entity Data Source to work with Entity Framework 6

I'm trying to use Entity Data Source Control to access my database first Entity Framework model but I can't get it to work with Entity framework 6. It gives me an error saying its not compatible with Entity Framework 6 and instead directed me to install Microsoft.AspNet.EntityDataSource from Nuget which I've done. but for some reason I can't configure it using the wizard. In design view, it doesn't show the little arrow to open the smart tasks panel.
I'm new to ASP.NET and don't know how to configure it in markup view
which data source (or perhaps another technique) should I use to access data objects in Entity Framework 6?
I don't think you can use the wizard to configure EF6 EntiyDataSourceControl. The wizard only works with EF5. You need to configure the EF6 EntityDataSourceControl in code. Here is a corresponding ticket.
I have gone through same situation as yours.Finally this solved the issue,
Uninstalled EF6 and installed version 5 of Entity Framework through Nuget Package Manager Console, then it worked fine

Using Entity Framework 6 with EntityKey

I am trying to upgrade a big data project from EF 5 to EF 6. But when I run the code generation in EF6 tool the references to the related tables are no longer there.
So the following line of code no longer works.
dbTradeAllocation.ChargeTypeReference.EntityKey = new EntityKey("ICEEntities.SystemData", "ID", TradeAllocation.ChargeType);
Does anyone know if EntityKeys are still supported in EF6 ?
Thanks Paul
EntityKey is supported in EF6. However you cannot run EF5 code generation in EF6 - it won't work since there were changes in namespaces. I touched a little bit on this in my blog post about changes to EF Tooling in VS2013 - you can find the blog post here. If you want to use EntityObject/ObjectContext entities in EF6 you need to use EntityObject generator for EF6 which you can get from VS Gallery (note it requires .NET Framework 4.5 on the dev box).

How to integrate my own structural annotations engine in the Entity Framework designer?

In the accepted answer to this SO question there is an explanation about structural annotations, a way to customize the data on the EDMX files generated by the Entity Framework designer. This feature is used by the Portable Extensible Metadata framework in order to add validation information to the entities defined in an EF model, by adding extra entries to the "Properties" window of the created entities and its properties.
My question is: what should I do if I want to create my own custom structural annotations engine? That is, I want Visual Studio to show some extra entries in the properties window for the EF entities; and I want to integrate my own code with the EDMX code generator in order to generate structural annotations. I guess that I need to create a Visual Studio extension but apart from this, I could not find any further information anywhere else. Where should I look for information on this subject?
Entity framework has very low extensibility on ORM layer but it has surprisingly good extensibility on designer layer. The core of extensibility is based on few interfaces which can be implemented to add custom features to EDMX designer as VS extension.
The step by step process of adding custom property to designer is described in Entity Framework 4 in Action book. You can also use Designer Extension Starter Kit to get some prepared templates and kick start for creating your own extensions.
These features targets EFv4. Extension starter kit doesn't work with June 2011 CTP and its new designer.

EntityFramework gives IDisposable error

I use EF for the back-end DataLayer in my asp.net websites. I create a class library and add the Model in it, reference it and use it from the ASP.NET Website. But this time, I generated the model from database but it seems does not implement IDisposable, and the methods I used to see are not there. DeleteObject , SaveChanges etc. There are only Two tables in the DB and the Model was generated with only the TableSets and two methods AddToTableSet ... Had anybody encountered such a problem?
alt text http://techlipse.net/EF-problem.jpg
Did you extend the generated ObjectContext and then perhaps rename it in the EDMX? You might be looking at your part of the partial class here without the generated part.
What does the Properties panel say for your EDMX for "Entity Container Name"?
When you right click on Entities and go to definition do you get to the correct generated class?
And lastly, but probably most likely, did you perhaps delete the Reference to System.Data.Entity from the project or not reference it in your web project?
Is you web project even a Web Application project???
I have my Entity Framework code in its own project, and was referencing it from a separate project. NuGet sets EntityFramework only on the EF project, which is how the reference gets automatically configured to the latest version. To fix this error:
Tools -> Library Package Manager -> Manage Nuget Packages for Solution
Select Installed Packages and find Entity Framework
Click the Manage Button, and check all the project that will be accessing the EF Data Model.