Print Page | Close Window

EntityManagerSaveException: No CodeFirst entities were found

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2967
Printed Date: 13-May-2026 at 3:08pm


Topic: EntityManagerSaveException: No CodeFirst entities were found
Posted By: Engo
Subject: EntityManagerSaveException: No CodeFirst entities were found
Date Posted: 21-Sep-2011 at 2:51am
I'm trying to store a single new entity which I create with the following code:

var systemUser = mgr.CreateEntity<SYSTEM_USER>();
systemUser.EntityAspect.AddToManager();
systemUser.syspasswordhash = vsPasswordHash;
systemUser.sysuser = psUsername;
systemUser.sysdomain = psDomain;
mgr.SaveChanges();

This gives me the following exception (when SaveChanges is invoked)

[IdeaBlade.EntityModel.EntityManagerSaveException] {"Key 'FortressManager': Error in DbKey EntityManager:  No CodeFirst entities were found in assembly model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"} IdeaBlade.EntityModel.EntityManagerSaveException


Maybe someone can help me here, because I did not use any code first functionality (just generated the model from the database).




Replies:
Posted By: sbelini
Date Posted: 21-Sep-2011 at 6:45am
Hi Engo,

It looks like you are missing the connectionString in your App.config/Web.config file.

Sorry the error message is not very clear. The message will be more informational on DevForce 6.1.3.

Regards,
   Silvio.


Posted By: Engo
Date Posted: 21-Sep-2011 at 10:37am
Thanks for your answer. The problem was that I renamed the connection string but did not copy that renamed value into the server config.


Posted By: Louis
Date Posted: 14-Nov-2011 at 2:10pm
Hello, I am receiving the same error message.
My connection string is properly set.   I had generated the model from an existing database so I was surprised to see a need for CodeFirst. Here is my stack trace.  I see it coming from CreateDbContext().  Is there possibly something I need to add to my model? 
 

IdeaBlade.EntityModel.EntityServerException: Key 'EnvisionShellEntities': Error in DbKey EnvisionShellEntities: 

No CodeFirst entities were found in assembly Decade.CIW.Connectors.Envision4.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --->

System.ArgumentException: Error in DbKey EnvisionShellEntities:  No CodeFirst entities were found in assembly Decade.CIW.Connectors.Envision4.Model,

Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

 

IdeaBlade.EntityModel.Edm.DbKey.get_Builder()

IdeaBlade.EntityModel.Edm.DbKey.CreateDbContext()

IdeaBlade.EntityModel.Edm.DbKey.CreateContext()

IdeaBlade.EntityModel.EntityManager.HandleEntityServerException(Exception ex, Boolean tryToHandle, PersistenceOperation operation, Boolean throwOnError)

IdeaBlade.EntityModel.EntityManager.ExecuteServerQuery(IEntityQuerySurrogate entityQuery)

IdeaBlade.EntityModel.EntityManager.ExecuteFetch(IEntityFinder finder)

IdeaBlade.EntityModel.EntityKeyFinder.ExecuteFindThenFetch()

IdeaBlade.EntityModel.EntityKeyFinder.Execute()

IdeaBlade.EntityModel.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)

IdeaBlade.EntityModel.EntityManager.ExecuteQuery(IEntityQuery query)

Decade.CIW.Connectors.Envision4.EnvisionClassicEntity.GetAgencyInformation() in C:\Decade Software\Corsair\Applications\CERSIntegrationWizard\Decade.CIW.Connectors.Envision4\EnvisionClassicEntityRead.cs: line 26

Decade.CIW.Connectors.Envision4.Tests.EnvisionClassicEntityReadTest.GetAgencyInformation_WhenCalled_ReturnsResult() in C:\Decade Software\Corsair\Applications\CERSIntegrationWizard\Decade.CIW.Connectors.Envision4.Tests\EnvisionClassicEntityReadTest.cs: line 77



Posted By: kimj
Date Posted: 14-Nov-2011 at 5:56pm
Hi Louis,
 
There's nothing you need to add, but for some reason DevForce thinks your model is a Code First one, and is following that path.  Can you double check that the connection string or edmKey "EnvisionShellEntities" is in your server's config file, and that the contents of the string contain the usual "metadata=..."?


Posted By: Louis
Date Posted: 14-Nov-2011 at 11:51pm
Thanks Kim

In case I didn't mention it explicitly before, I was getting this error through a unit test. 
 
After I created a small console test app (with the proper connection set in the app.config) and called the same method .. the query finally works.

I will refactor the unit test to set the connection there.

Thanks




Posted By: kimj
Date Posted: 15-Nov-2011 at 9:25am
In a unit test, be sure the app.config is deployed.  The debug log will tell you if it found the config or is using a "fall back".



Print Page | Close Window