How to start using EntityFramework 4.1 (or 4.3 currently) - asp.net

I've installed EntityFramework through nuget (should I do this for every project? Or can I just reference the assemblies? Where are they 'installed'? Sorry new to nuget)
I add a new "Ado.NET Entity Data Model" to my project and import tables from the database. However the context is added as ObjectContext not as the latest DbContext as I would presume. Am I missing something here?

Yes, install the package for each project. The assemblies are installed in a packages folder in the solution folder.
The ADO.NET Entity Data Model is for Database First. Read an explanation of Database First vs. Model First vs. Code First here:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

A great place to start is http://asp.net. Read the tutorials. They cover data access with EF for both WebForms and MVC.

Related

How to apply new changes to current database in code fist EF core?

I have a project that coded with DotNet Core code first.
Now, there is a lot of real data on the database and i have to add some features with many tables and new relations to this project.
How can I apply these tables and their relations to the Database without adding manually?
Is there any way to use Add-Migratiosn and Update-Database to apply new changes via EF core instead of manually applying?
If you have not many changes to your DBContext you can remove it and use Scaffolding to create new DbContext from the existing database schema. You can find more information in the official Microsoft documentation here.
It is better to use only one entity framework database approach either Database-First or Code-First.

Entity Framework Core - Scaffold existing database to one or group of class files

As stated in this tutorial, I can scaffold code-first EF Core from an existing database using Scaffold-DbContext in the Package Manager Console.
It's all good but my problem is that it scaffolds separate class files for each table and another for the context class. I find this a bit messy if I have too many tables.
I can rearrange it all by hand but Is there a way to scaffold everything to one class file? Or maybe having the context class on a separate file and then group the tables to another file per schema.
This behavior is not an option of EF Core scaffolding as of 1.0.0.

ADO.Net in ASP.Net 5 MVC6?

I am trying to locate the Entity Data Model Wizard that allows you to populate the database schema into a DatabaseModel.edmx file so I can create my model based on that.
I've included the EntityFramework dlls into the project.json file but not too sure if in this new version of ASP.NET MVC this wizard is available anymore...
I've seen that the scaffolding that generates the Model classes is done through command line now but not sure if that has anything to do with the wizard I was talking about above.
Thanks!
"Prior to EF7 there are two ways to store models, in the xml-based EDMX file format or in code. Starting with EF7 we will be retiring the EDMX format and having a single code-based format for models."
Source: http://blogs.msdn.com/b/adonet/archive/2014/10/21/ef7-what-does-code-first-only-really-mean.aspx

EntityFramework 7 - CodeFirst - SQLite - Manage DB using ApplyMigrations at runtime

I am well on my way to utilizing EF7 CodeFirst with SQLite...but really want to employ DB Migrations at runtime. This is a desktop application (Click-once deployment) meant to sync with a main database when connection is available, and provide offline data when no connection is present.
I have pulled down the nuget pre-release versions and all is working, except I cannot find any documentation of how to apply the migrations at runtime. I can successfully Add-Migrations and manually Apply-Migrations...but need a way to programatically Apply-Migrations at runtime.
I've also browsed the EF7 open-source project, but could not get anywhere there.
Versions I'm using: Latest Pre-release as of 9/15/2015
EntityFramework.Sqlite v7.0.0-beta7
EntityFramework.Relational v7.0.0-beta7
EntityFramework.Commands v7.0.0-beta7
...et al...you get the picture.
I am asking for help to apply runtime migrations...or what is the documented/recommended path for programatically maintaining a local/embedded db using EF7 CodeFirst SQLite?
UPDATE:
I went back to EF6 with SQLite but then found out that there is not SQLMigrationGenerator for SQLite.
EDIT:
I believe ApplyMigrations() method referenced in one of the notes has been deprecated. Searching the repository, there is no reference to "ApplyMigrations".
Today you can invoke the extension method Migrate on the DatabaseFacade.
This method is only available when the using Microsoft.Data.Entity statement is present. It comes from the RelationalDatabaseFacadeExtensions class that is part of the EntityFramework.Relational package.
Still have to find out how to migrate up and down from the API.

System.InvalidOperationException: Mapping and metadata information could not be found for EntityType

I have an ASP.NET 4.0 web application that uses Entity Framework 4.3.1 and Self-Tracking Entities. It works fine until I add another ADO.NET Entity Data Model (.edmx) file to it. After that the project compiles without any errors, but as soon as it calls a self-tracking entity object, the application produces the System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'namespace.classname'.
I have tried adding the second ADO.NET Entity Data Model into a different namespace - but that does not help.
If I remove the added .edmx file from the project, the problem disappears.
If I remove the Self-tracking entity files (Model.tt and Model.Context.tt), the problem disappears.
It looks like Self-Tracking Entities cannot function properly when there is more than Entity Data Model.
Has anyone else experienced and solved this problem?
Make sure to use consistent Context generation throughout your solution.
Use the EF 5.x DbContext Generator on each of your Entity Data Models. You can either download the template via the ExtensionManager (search for EF 5.x) or here
I think self tracking entities are not supported from 4.1 (DbContext) onwards.
We had a few problems at work when upgrading from 4 to 4.2 with ste and we ended up reworking all to use DbContext and getting rid of ste. Since then it works like a charm!

Resources