Entity Framework - Error 11007: Entity type is not mapped. - entity-framework

I have a problem when I got the lasted .edmx.
I get a message that says
Error 11007: Entity type 'pl_Micro' s not mapped.
Looking at the designer view, I do see that this table does indeed exist.
How can I overcome this meesage?

From MSDN:
Error 11007: Entity Type Is Not Mapped
This error occurs when an entity type in the conceptual model is not mapped to the data source. To resolve this error, map the entity type to the data source. Look at the MSDN link
How to: Map Entities to Database Tables

I get this error when I move a database table to a different schema or delete a database table. In this case Entity Framework doesn't seem to update the edmx file correctly when you Update Model from Database....
The way I resolved this was to do a text search for the name of the offending entity. I then removed all references to this in the xml view of the edmx file, deleted the corresponding cs file that defines the entity, and any other references in the project.

This error was passed to me by the SQL Server Authentication server did not have the necessary permissions and could not see the entities.
Confirm that your sql user has the necessary permissions in the database.

This happens also when you import tables via diagram in edmx and then you point in app.config to different instance of database (switching from dev db to test db for example)

I got this error because I had copy pasted an entity and modified it. Restarting visual studio resolved this.

Correct, close visual study, enter the * .edmx file with a notepad ++, sublime text, notepad, etc., search the table, search the column and modify the column size (MaxLength), in all matches, in My case was 2, but they can be more. Start visual studio and the change is already accepted.

I got this error because I had to update the table column type.
Refresh table in SQL server and re-add table in the entity framework for resolving this.

Related

Entity framework error on updating model from database and vice versa

Here is what happens when I try to update model from database with VS express 2013 for the web, EF6.1.1 and .NET framework 4.5.
In this case I just added a field to a table in the table definition and updated the database.
After that I right click update model from database in the EDMX model view and I get this error message:
An exception of type ‘System.runtime.interopServices.COMException’
occurred while attempting to update from the database. The exception
message is: ‘A file or folder with the name ‘Model.Context.tt’ already
exists. Please give a unique name to the item you are adding or delete
the existing item first.
I noticed that I get the same error message when I try to generate the database from the model.
I tried the following methods:
How do you update an edmx file with database changes?
http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#.VMYYRv7A7mH
but none of them worked.
I also found that https://entityframework.codeplex.com/workitem/1104 and it seems that it has been resolved with “commit 7e8331d1d22d (EFTools repo)”.
Anyone can help me on how to solve my problem or on what is “commit 7e8331d1d22d (EFTools repo)” ?
Thanks
Boid’
It's an old question but I just run into the same issue. Finally found a solution in this bug report. Check if you have any *.tt files that are not added to solution and remove them. That fixed the problem for me.

EF6 Model First: Unable to generate database from model after adding new entities

I created a new project and added an empty data model. I added a few entities and properties and then generated the database according to this tutorial. So far, so good. I then went back and added additional entitities.
Now, I am no longer able to Generate Database From Model... because I receive an Error 11007: Entity Type 'xxxx' is not mapped for all of the new entities I added. According to msdn, I can follow the instructions here to resolve my mapping issue between conceptual and storage models. However, it appears these instructions assume the entities are already present in my storage model (which they are not). When I try to manually map them, the only two tables I have to choose from are the original two tables I created.
I appreciate any help you can offer.
This was a phantom error of sorts. I had another error with a default value I was trying to set for a datetime that appeared at the bottom of my error list. I resolved this error and everything is now working as it should.

Entity Data Model Wizard not creating tables in EDMX file

I'm trying the database first approach by creating an ADO.NET Entity Data Model using the wizard with the Adventureworks2012 DB.
Testing DB connection works, and the connection string is added to the App.Config.
I'm selecting all the tables except the ones marked as (dbo) AWBuildVersion, DatabaseLog, and ErrorLog.
When the wizard finishes the .edmx file is blank, and if I view the file in XML view the EntityContainer is empty.
After the model is created it returns this error in the output window:
Unable to generate the model because of the following exception: 'The
table AdventureWorks2012.Production.Document is referenced by a
relationship, but cannot be found.
I'm using VS 2010 & .NET Framework 4.0
It seems that Entity Framework does not know how to deal with data types like hierarchyid set on a table field. I removed the Production.Document table for the list of entities to include solving my problem.
Note also that this reference below was for Adventureworks 2008R2 with EF version 1.0 from Code Plex SQL Sever, and I am using Adventureworks 2012 from the same CodePlex site using EF version 4.4.
Reference: http://msftdbprodsamples.codeplex.com/wikipage?title=AW2008Details
Note: EF 1.0 Compatibility Issues
The Entity Framework team would like us to let you know that AdventureWorks2008 is a little bit ahead of the curve in terms of the Katmai features it uses. Some datatypes in AdventureWorks2008 (such as hierarchyid and geometry) are not supported in the entity framework. The workaround is to exclude tables like Production.Document from your model if possible since there is currently no support for the hierarchyid datatype in Entity Framework 1.0. Unfortunately the Entity Framework tooling which updates your model from the database will pull in tables like Production.Document even if they were specifically excluded when the model was created, so use of that feature on AdventureWorks2008R2 is not supported at this time. We look forward to a follow-on release of Entity Framework which has full SQL Server 2008 type support.
Last edited May 25, 2010 at 2:22 PM by bonniefe, version 17
There is a way to get around this IF you're trying to learn from this example and not doing anything meaningful. I deleted the foreign keys to the offending table and removed it and was able to succesfully get
Uncheck [Allow Nulls] Check-boxes (in the table design) for all the foreign keys of the not created Tables (Tables not converted to the model).
Then you can update your model to retrieve those tables by doing the following steps:-
Step 1 - Right click some where in your .EDMX file's design (i.e. Model1.EDMX [Diagram1].
Step 2 - then from the Context Menu select / Update Model from Database....
Step 3 - then select "Add"
Step 4 - then expend "Tables" Check-Boxes and select your desired tables (tables not created first time).
Step 5 - then click Finish button.
Step 6 - Save the the solution and hope everything will be Ok.
Note: I'm using Visual Studio 2013.
Good luck.

How to create read-only entity in Entity Framework?

My app is purely read-only so I don't want to generate all the update & delete code, and I don't want to pull in all fields from all tables. Some of these fields are not nullable so I am getting errors from EF here becasue there is no default value to save.
In my previous ORM (Wilson) you could just flag an entity as read-only in the XML. I've seen a few posts showing convoluted solutions to this. Am I missing something? Why isn't this straight forward?
I see that the RIA services wizard has a check box for this for each entity...
The problem is that you have a non-nullable field in your SSDL which isn't in your CSDL.
You can manually remove the column from SSDL and the EF will be happy. But the designer will re-add the column when you update the model. So you can either remove it again or update your model from a variant of the DB which doesn't have that column.

Number of members in conceptual type does not match with number of members on object side type

I'm using .net framework 3.5 SP1.
After adding a column to one table in Sql Server (as well as changing an existing column from allowing nulls to not nullable), I can no longer run my project without getting this error:
The number of members in the
conceptual type
'XBRLDimensionalModel.axis_t' does not
match with the number of members on
the object side type
'EOL.Xbrl.Persistence.Data.axis_t'.
Make sure the number of members are
the same.
I gave up trying to find and fix the generated code. I now have deleted all my local entity-related files and re-generated them by starting over from scratch and adding a new item (ADO.NET Entity Data Model). I still get this error.
The only way I can run the project now is to undo all my pending changes and use the last version from source control, and of course change the two modified database columns to nullable.
From all I've read so far it seems like I simply should have been able to "update" my model from the database. That resulted in this exception (above). But now I'm totally confused that even with a complete regeneration of the entity model and supporting classes I'm still getting that error.
I changed the property on my edmx model: "Metadata Artifact Processing" to "Copy to Output Directory". The Designer.cs, csdl, msl, ssdl files all seem to be consistent with the latest DB changes.
The exception is being thrown the first time my entityModel instance is referenced. So it is prior to any loading or saving of the data from the changed table.
any ideas where I'm going wrong?
Thanks,
TG
This error can also happen if the EDMX file was changed outside Visual Studio. Right click on the EDMX file and click "Run Custom Tool"
Open your model as XML. Remove all references to that type from the CSDL. Save and close, then reopen in the GUI. Now you should be able to update model as usual. If that doesn't work, do the same thing, but remove from MSL as well.
This seems a little verbose for a comment so I'm adding this as another answer:
In response Craig's suggestion I opened the edmx file in an XML viewer and removed all references to Axis_t (including the associations due to Foreign Keys). From the entire file.
I then "updated" the model by opening the edmx file as the GUI interface, right-click | refresh from database | Add (tab) which now only lists the Axis_t table. I added the table which seemed to work fine and included my new column and the column was mapped correctly.
I then ran the project to the same result. Same error as posted above.
I have now reverted back to what was in source control as well as changing the database columns (new one and modified one) as nullable. The project runs fine. I still have not successfully been able to implement the new DB column in EF. It behaves as if there is some stored/compiled version of the model which is not being updated via the "update" process.
When changing a foreign key from nullable to non-nullable (or vice-versa), be sure to change the association multiplicity from 0..1 to 1 (or vice-versa). The designer sometimes misses this in an update from the database.
Right click on your edmx file and open with XML.
Find the incorrect data types and change them.
Save file.
This worked for me.
I was facing the same issue, when I added one column to db and added respective property to entity(edmx).
I was also using source control for my solution. As I noticed, while saving changes to any file, save action prompts with overwrite option.
So, I overwritten the designer.cs as well config file and problem gets resolved.
regards,
bhushan
This has happened to me when I am working on two versions of the same application (with Model differences) that compile into the same folders.
It appears that Visual Studio doesn't "clean out" the "obj" temp folder properly and some fragments of the old model are still in there.
If I simply delete all files from the "obj" folder and re-compile this error goes away.
The Model in each version is perfect which was driving me crazy.
Not saying this is the answer to the OP's question but it is definately another reason for this error.
Steve
I had this same issue for hours. Found that in my Designer.cs file one of the properties of my entity was missing its attributes. (Don't know how this happened?)
[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
[DataMemberAttribute()]
public global::System.Int32 ContractCapacity
Now the error message makes sense, this was the missing DataMember. Once the attribute was added IT WORKED!!!
Here's a nightmare scenario that I just experienced: I have an MVC2 website and a WCF service that are built separately, but share a configuration. Within both projects, I used the same Entity Container Name; therefore I picked up the same connection string for both projects. Eventually the metadata got out of sync between the two and caused this error. The obvious solution was to not use the same Entity Container Name in the two projects; changing to a different name allowed me to specify unique connection strings, and therefore metadata, for each component which avoided the problem.
Now that I figured it out, it's obvious, but I had a tense hour or two!