New Posts New Posts RSS Feed: Error in model generation (code first)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error in model generation (code first)

 Post Reply Post Reply Page  12>
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: Error in model generation (code first)
    Posted: 22-Sep-2012 at 1:05pm
Hi,

I am trying to migrate from 2010 to 2012.

When I try to build I get this error when it was working in the previous with the 6.1.8.

Erreur 1 CodeFirst entities were found in this assembly, but an EntityManager or DbContext was not.  You must define a container for these entities in this assembly. xxx.Common.Domain


This assembly doesn't contains any entitymanager or DBContext because it hosts the base class (all abstract) for all the others domains assemblies.

Is it now mandatory to create a DBContext or entitymanager in any assembly hosting a code first class even if all are abstract  ? 
I created an internal empty entityManager to be able to continue the migration but I feel I shouldn't have to.


Another issue (also working in 6.1.8)  :

Erreur 4 An error occurred during metadata generation and a metadata file could not be created.  Error: You cannot use Ignore method on the property 'AdressPrincipal' on type 'xxx.Global.Domain.Entities.Professional' because this type inherits from the type 'xxx.Global.Domain.Entities.Person' where this property is mapped. To exclude this property from your model, use NotMappedAttribute or Ignore method on the base type. xxx.Global.Domain

I already have the NotMapped attribut on the property AdressPrincipal (below the code)

    [DataContract(IsReference = true)]
    public abstract class Personne : BaseAuditEntity
    {
        [DataMember]
        public int Id { get; set; }

        ...

        [NotMapped]
        public Adresse AdressPrincipal {... }
    }

    public class Professionel : Person
    {
      ...
    }

I don't know, generaly speaking, if I should put the DataContract attribute on  the inherited class if the parent class has it
Anyway I tried both case and both give this error



Edited by Walid - 22-Sep-2012 at 2:24pm
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 22-Sep-2012 at 2:25pm
Updated
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 2:56am
Another error which doesn't exist in 6.1.8 :


Tâche "EntityModelMetadataDeploy"
  In EntityModelMetadataDeploy.  Parms:  Assembly='C:\Dev\Dev\MigrationDFandCocktail2012\Company\Domains\Management\Company.Management.Domain\bin\Debug\Company.Management.Domain.dll', TargetFolder='C:\Dev\Dev\MigrationDFandCocktail2012\Company\Domains\Management\Company.Management.Domain'
  IdeaBlade.VisualStudio.Build.Tasks, Version=7.0.0.0, Culture=neutral, PublicKeyToken=287b5094865421c0
  Trying model metadata discovery for C:\Dev\Dev\MigrationDFandCocktail2012\Company\Domains\Management\Company.Management.Domain\bin\Debug\Company.Management.Domain.dll
  Creating metadata from DbContext 'ManagementDbContext'
  Searching for connectionString named 'CompanyDBManagement': not found
  A connection string was not found but metadata discovery has detected that the DefaultConnectionFactory is overridden.
C:\Dev\Dev\MigrationDFandCocktail2012\Company\packages\IdeaBlade.DevForce.Aop.7.0.0-beta1\tools\IdeaBlade.DevForce.Common.targets(110,5): error : An error occurred during metadata generation and a metadata file could not be created.  Error: La référence d'objet n'est pas définie à une instance d'un objet.
  EntityModelMetadataDeploy: No metadata files generated.
Exécution de la tâche "EntityModelMetadataDeploy" terminée -- ÉCHEC.

I first though the problem could come from the connection string but here is the log from model which build :

Creating metadata from DbContext 'StockDbContext'
  Searching for connectionString named ' CompanyDBStock': not found
  A connection string was not found but metadata discovery has detected that the DefaultConnectionFactory is overridden.
  Model metadata created for  CompanyDBStock
  Model metadata for WSoftDBStock.ibmmx is unchanged
Exécution de la tâche "EntityModelMetadataDeploy" terminée.



Any clue what could be the problem ?


Edited by Walid - 24-Sep-2012 at 3:22am
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 3:27am
Walid,
Did you completely uninstall DF 2010? Code-First builds currently do not work with DF 2010 and DF 2012 installed side-by-side.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 3:30am
Originally posted by Walid

 
When I try to build I get this error when it was working in the previous with the 6.1.8.

Erreur 1 CodeFirst entities were found in this assembly, but an EntityManager or DbContext was not.  You must define a container for these entities in this assembly. xxx.Common.Domain


This assembly doesn't contains any entitymanager or DBContext because it hosts the base class (all abstract) for all the others domains assemblies.

Is it now mandatory to create a DBContext or entitymanager in any assembly hosting a code first class even if all are abstract  ? 
I created an internal empty entityManager to be able to continue the migration but I feel I shouldn't have to.


Like for the global.asax, the server package created a Devforce.cf file that I didn't notice before.

Removing this file fixed it.

Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 3:33am
Originally posted by mgood

Walid,
Did you completely uninstall DF 2010? Code-First builds currently do not work with DF 2010 and DF 2012 installed side-by-side.

I am doing the migration on a clean VM under Win8 where I only installed VS2012 and devforce/cocktail thru nuget


Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 4:04am
Originally posted by Walid

Originally posted by Walid

 
When I try to build I get this error when it was working in the previous with the 6.1.8.

Erreur 1 CodeFirst entities were found in this assembly, but an EntityManager or DbContext was not.  You must define a container for these entities in this assembly. xxx.Common.Domain


This assembly doesn't contains any entitymanager or DBContext because it hosts the base class (all abstract) for all the others domains assemblies.

Is it now mandatory to create a DBContext or entitymanager in any assembly hosting a code first class even if all are abstract  ? 
I created an internal empty entityManager to be able to continue the migration but I feel I shouldn't have to.


Like for the global.asax, the server package created a Devforce.cf file that I didn't notice before.

Removing this file fixed it.

 
The DevForce.cf file gets added by the Code-First package. You shouldn't install the Code-First package to a project that doesn't contain model classes.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 8:04am
Well it contains the bases class of my entities shared with all my domains.
So I need access to Aop for the ProvideEntityAspect attribut


Any idea what/where I should look for to fix the error I did mention earlier ? 
error : An error occurred during metadata generation and a metadata file could not be created.  Error: La référence d'objet n'est pas définie à une instance d'un objet.
The error message doesn't give me any indication on what to do.

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 11:05am
Regarding the issue with applying the Code First package to your base class assembly - we will need to look at making this cleaner.  For now, removing the .cf file will ensure that the DevForce metadata deploy task doesn't kick off.  Instead of installing the package, though, you can just reference the IdeaBlade.EntityModel.Aop assembly (by browsing to the packages folder holding the assemblies).
 
We haven't seen this NullReferenceException issue, and as you say the error message doesn't help.  Is the model project in which you get this error the one referencing the assembly containing the base class?  You mentioned that you created an empty EntityManager to work around the problem building the assembly holding the base class, so one thing to try would be removing this EM.
 
Regarding the attribute problems you mention in your first post, these are due to EF 5 data annotation changes.   We hadn't seen these issues before now, but some quick googling shows that others are having this issue with using NotMapped when inheritance is involved.  We don't have a workaround to suggest right now, but as soon as we do we'll let you know.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 11:22am
Yes I found those post too.
The problem in most of them was that in EF5 & .NET4.5 the NotMappedAttribut is in the namespace System.ComponentModel.DataAnnotations.Schema while it is in System.ComponentModel.DataAnnotations while targetting .NET4

When I made my migration I was aware of those problems around EF5 so I targeted .NET4.5 prior upgrading to EF5.
The NotMapped attribut correctly use the good schema namespace.

The weird part is in my base class I have a NotMapped attribut on the EntityAspect property and this one doesn't cause any trouble.
I checked all the reference in the project (I even did compare with the reference on the Temphire model) and nothing is different.

So right now I am stuck :(

For the null reference exception I am still investigating. It might be another model issue because if I comment all my EntityTypeConfiguration I can compile and generate a .ibmmx (of course this file isn't good as it miss some configuration).

Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 12:22pm
I found out for the null reference exception.

in one entity class I had this delcaration :

[DataMember]
public TypePiece? TypePiece { get; set; }

where TypePiece is an enumeration

The correct sentence is

[DataMember]
public int? TypePiece { get; set; }


Pretty hard to find, specially since this model didn't throw any exception with EF 4.3


Only the [NotMapped] issue is left for now.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 2:12pm
I'm not able to reproduce the NotMapped issue, although it could be that my model is too simplistic.
 
One other thing to look at is whether you have an older EntityFramework assembly in the Global Assembly Cache, and also ensure that the EntityFramework.dll is in the bin folder of the application project.
 
If that looks good, would you be willing to send us more of your model code?  I'm specifically interested in whether you have a DbContext defined, the full definitions of "Personne", "Adresse" and "Professionel", and what flavor of inheritance you're using.  The EntityManager, and DbContext if present, would help too.  You can send either to me via a PM, or to IdeaBladeSupport.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 2:18am
sent you a link to download the solution in PM

Thanks
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 3:31am
Found on codeplex there is a bug about NotMapped and inheritance but regarding the suggested fix I am not able to say if it is related or not.

http://entityframework.codeplex.com/workitem/481?FocusElement=CommentTextBox
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 10:21am

That looks like the bug.  I saw that mentioned on StackOverflow too, but we're not interested in modifying the EntityFramework source code, at least not right now.  

I think you can work around the issue by using the Ignore method instead of the NotMapped attribute.  I was able to get the model built when I added the following to TiersConfiguration:

Ignore(p => p.AdressePrincipale);
Ignore(p => p.TelephonePrincipal);

.. also making sure to remove the NotMapped attribute from these properties.

Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 1:42pm
I will try the Ignore() once I get the domain working. Actually only the Security model works, the 3 others aren't and all get the same error :

Unable to create an instance of EntityManager: CommunEntities. Required constructor not found. Please add the following constructor: public CommunEntities(IdeaBlade.EntityModel.EntityManagerContext).

Each entityManager owns this constructor I you can see in the model I sent you.
What could cause this error ? everything was working in previous version.

In the Log, the domain assemblies are probed on the server.
Probe Assemblies: xxx.Common.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null :: xxx.Commun.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null :: xxx.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 

I can see the log when it instanciate the security domain :
Metadata file 'xxx.Security.xxxDBSecurity.ibmmx' loaded from assembly 'xxx.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 

but nothing about the xxx.Commun.Domain model I currently try to use.


below the full error message :

La composition a produit une seule erreur de composition. La cause initiale est fournie ci-après. Pour plus d'informations, passez en revue la propriété CompositionException.Errors.

1) Unable to get metadata for xxx.Commun.Domain.Entities.News. Make sure it is a valid entity type or POCO type with a KeyAttribute

Résultat : Unable to initialize EntityManager
Unable to get metadata for xxx.Commun.Domain.Entities.News. Make sure it is a valid entity type or POCO type with a KeyAttribute

Résultat : Une exception a été levée par la cible d'un appel.

Résultat : Unable to create an instance of EntityManager: CommunEntities. Required constructor not found. Please add the following constructor: public CommunEntities(IdeaBlade.EntityModel.EntityManagerContext).

Résultat : Une exception s'est produite lors de la tentative de création d'une instance de type xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork.

Résultat : Impossible d'activer le composant 'xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork'.
Élément : xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork -->  xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork -->  AssemblyCatalog (Assembly="xxx.Commun.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Résultat : Impossible d'obtenir l'exportation 'xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork (ContractName="xxx.Commun.Services.UnitsOfWork.ICommunUnitOfWork")' du composant 'xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork'.
Élément : xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork (ContractName="xxx.Commun.Services.UnitsOfWork.ICommunUnitOfWork") -->  xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork -->  AssemblyCatalog (Assembly="xxx.Commun.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
La composition a produit une seule erreur de composition. La cause initiale est fournie ci-après. Pour plus d'informations, passez en revue la propriété CompositionException.Errors.


This migration is really a pain in the ass, I started saturday and I still don't have a running application ;(





Edited by Walid - 25-Sep-2012 at 1:55pm
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down