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

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.

Related

EF5 keeps referencing property that no longer exist

I have an EF5 Model, I renamed a couple of tables and fields because they were spelled wrong. Now when I re update the model from the DB it makes all the correct associations and entities and context all change. But I keep getting this error below. Mind you the field "BrowserDetailId" no longer on any table nor in Fk relationship. I get this error only at run time, and I cant find where it thinks the FK relationship still exists.
Schema specified is not valid. Errors: The relationship 'PortalModel.FK_LoginActivity_LoginAttempts' was not loaded because the type
'PortalModel.LoginAttempt' is not available. The following information may be useful in resolving the previous error:
The required property 'BrowserDetailId' does not exist on the type 'Portal.Entities.LoginAttempt'.
The relationship 'PortalModel.FK_VerificationAttempts_Verification' was not loaded because the type 'PortalModel.Verification' is not available.
The following information may be useful in resolving the previous error:
The required property 'BroswerDetailId' does not exist on the type 'Portal.Entities.Verification'.
I have deleted edmx and related context and entities and recreated them, still get the error.
I have delete the FK's to the related to tables and updated the edmx model and still get the error.
I have created new edmx file and context and entites still get the error.
I have searched all the files in the solution and cant find any mention of the "BrowserDetailId".
I have been trying to figure this out for more time then i would like to admit, any help would be great.
The database is SQL Server 2008

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

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.

Entity framework, adding custom entity to diagram

I'm using the entity framework that comes with 3.5sp1, and I'm trying to add a custom entity that I will propulate with searchresults from a stored procedure. But I have problems with the designer....... when I pick "Add + Entity" and give it a name, and hit save, the whole diagram stops working...... blah entities namespace could not be found..... all the other entities have lost its reference or summet. Works when I add a "table" to it that exists in database. But when custom it screws everything up.
How should I fix this? I've imported the function, I just need to add an entity for it...
I've read http://blogs.microsoft.co.il/blogs/gilf/archive/2009/03/13/mapping-stored-procedure-results-to-a-custom-entity-in-entity-framework.aspx but I cant get to step 3 since of all the errors when saving on step 2.
/M
Apparently I must have the primary key option checked when adding entity.

Entity Framework 4.0: Adding scaler property gives error (property it not mapped: 11009)?

I wanted to add a new property to one of my model (table). Basically its a property that doesn't exist in the database but i need to add it to my model so that the custom generation tool (self tracking entity generator) will create the the property inside the the custom generated file.
I added a scaler property, its a string and called testme but it gives me the following error, Anybody know how i can fix this?
Error 2538 Error 11009: Property 'testme' is not mapped.
I am confused why do i need to map it to a table... its a field that doesn't exist in the table ...
Any help really appreciated
Thanks
Generally, you add un-mapped properties to a partial class instead of via the model. That said, use discretion; un-mapped properties can be confusing, since they mostly can't be used in LINQ to Entities queries.
I encountered this problem and was able to resolve it by deleting the entity (a view) in tne designer and readding it by refreshing from the database. This occured after a major redesign of the database and rewriting the view.
I know this doesn't address your problem, but Googling for this error returns this question. Hopefully this answer will be useful to others who are new to EF and hit this message, like I did.
I've been generating my DB from my conceptual model. If I modify the model without updating the DB, then I see this error message.
At the moment I don't have any data in my model, so simply regenerating the DB from the changed model makes these errors go away.

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!