EF Mapping and metadata information could not be found for EntityType Error

后端 未结 13 1635
萌比男神i
萌比男神i 2020-12-05 09:42

I have encountered an exception when I use Entity Framework 4.0 RC. My Entity Framework model is encapsulated in a private assembly who\'s name is Procurement.EFDataProvider

相关标签:
13条回答
  • 2020-12-05 09:57

    a noob mistake, But I had the error when my access to the DB was with a Read Only username and password. Hope that my mistakes help others.

    0 讨论(0)
  • 2020-12-05 10:02

    I had a similar problem. I already had one EDMX file for one database using POCO classes and a Context object I wrote myself. When I added a second EDMX for a different database I used the POCO T4 template and then neither EDMX worked and threw the error you mentioned. To resolve it I scrapped my custom POCO and Context and used only the T4 Template and all worked well again.

    0 讨论(0)
  • 2020-12-05 10:03

    This is probably because EF can't find the embedded mapping information. Inside your connection string you'll probably have something like his:

    metadata=res://*/Models.MyModels.csdl|...etc
    

    That * is a wildcard, telling the object context to try and find the embedded mapping information from, I think, scanning all the loaded assemblies. If the assembly isn't loaded, EF won't find it.

    What you need to do is provide the connection string with more information about where your mapping information is embedded. Change the * to the specific assembly name of your mapping code:

    metadata=res://Procurement.EFDataProvider/Models.MyModels.csdl
    

    If that fails, find the Assembly and directly load it into your ObjectContext using:

    ObjectContext.Metadataworkspace.LoadFromAssembly();
    
    0 讨论(0)
  • 2020-12-05 10:03

    In my case it was essentialy the same issue, the mapping not being exactly as expected. What happened to me was that I had move a property in a "Table Per Hierarchy inheritance" from one of the subclasses to the base class and forgot to update the model.

    I have custom POCO and by copying the edmx file to a blank new project and let it autogenerate the entities, then compare them to what I had helped me in finding the difference.

    0 讨论(0)
  • 2020-12-05 10:04

    I was getting this error because I had more than edmx file in the same assembly with out proper use of custom namespaces.

    Here is what is said about the exception in System.Data.Objects.ObjectContext

    // Exceptions:

        //   System.InvalidOperationException:
        //     When the System.Data.Metadata.Edm.EntitySet from entitySetName
        //     does not match the System.Data.Metadata.Edm.EntitySet of the object’s
        //     System.Data.EntityKey.
        // -or-
        //     When the System.Data.Objects.ObjectContext.DefaultContainerName
        //     property is not set on the System.Data.Objects.ObjectContext and 
        //     the name is not qualified as part of the entitySetName parameter.
        // -or-
        //     When the specified type belongs to more than one entity set.
    
    0 讨论(0)
  • 2020-12-05 10:04

    I had a problem where I had added some columns to a table.

    In the Table Mappings, I had renamed the column names.

    Although I had run 'Transform All Templates' and rebuilt the application, I still got the 'The associated metadata type for type <> contains the following unknown properties or fields <>' error.

    The class for this table in Domain.Poco.tt was correct, but I found the corresponding class.Metadata.cs file in Domain.Poco.MetaData.tt had not updated, and had the new columns with the original names - not the new ones I'd specified in Table Mapping.

    Solution? I just deleted the offending metadata class, and re-ran 'Transform All Templates' and it was recreated correctly, with the correct column/function names.

    0 讨论(0)
提交回复
热议问题