The situation as follows:
we have one big MVC project with database first approach on EF5.0:
ObjectContext constructor:
namespace xxx.Models
{
(...)
public partial class xxxEntities : ObjectContext
{
#region Constructors
/// <summary>
/// (...)
/// </summary>
public xxxEntities() : base("name=xxxEntities", "xxxEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
(...)
connection string:
<add name="xxxEntities"
connectionString="metadata=res://*/Models.xxxModel.csdl|
res://*/Models.xxxModel.ssdl|res://*/Models.xxxModel.msl;
provider=System.Data.SqlClient;provider connection string="
data source=.;Initial catalog=xxxdb;
integrated security=True;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
We choose Code First for testing the new development on separated namespace.
connection string:
<add name="xxxCFContext"
connectionString="Data Source=.;
Initial Catalog=xxxdb;
Integrated Security=True;
User Instance=False;
MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
DbContext constructor:
namespace xxx.Models.CodeFirst
{
public partial class xxxCFContext : DbContext
{
static xxxCFContext()
{
Database.SetInitializer<xxxCFContext>(new ValidateDatabase<xxxCFContext>());
}
public xxxCFContext()
: base("Name=xxxCFContext")
{
}
(...)
We run add-migrations, update-database without problem, the build completed with success. But on the first time with the code-first db access:
xxxCFContext cfdb = new xxxCFContext();
foreach (Xobject xobject in cfdb.Xobjects)
Appear the error:
"Could not find the conceptual model type 'xxx.models.yyyclass'", but this yyyclass exist in edmx, NOT the codefirst part.
Uninstall EF5.0, install EF6.0 and the error disappeared. But i need the EF5.0 not the 6.0 alfa3 prerelease.
What's wrong? How can we use edmx mixed with codefirst with EF5.0?
I would be very grateful for any idea.
EDIT
I know this workarounds, but not help for me:
Have anyone used Entity Framework with code first approach mixed with Edmx file?
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
Could not find the conceptual model type
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
Entity Framework (4.3) looking for singular name instead of plural (when entity name ends with "s")
Building an MVC 3 App with Database First and Entity Framework 4.1
The problem of generating (with xxxmodel.Context.tt and xxxModel.tt) the large existing edmx heavily exploits the advantages of ObjectContext, so we can not simply change from the ObjectContext to the DbContext (behind the existing edmx).
Edit II
From DB First to CodeFirst, we choose the following:
- Moved from old edmx file to Code generation. With EF 5.x DbContext Fluent Generator was generated the model objects, so we have the model objects.
(Right-click into EDMX editor and add code generation item. If you do not seem, to be installed: Tools menu, Extensions and Updates, EF 5.x DbContext Fluent Generator)
- The model objects and the context is copied from the EDMX.
- The EDMX was deleted anything that was under him.
- Set the ConnectionString from was difficult EDMX-style to simple codefirst form.
and tadam, in about 10 minutes, we moved from Database First to Code First. During development, with existing 80 tables in db.
run Enable-Migrations in Power Management Console, and continued with CodeFirst.