Can't select the database when updating EF model - entity-framework

I have an edmx model
I right click on it and select Update model from database
The wizard show up .It normally show me Choose Your Data Connexion, but not anymore. Now it show me directly Choose Your Database Objects
How can I select a different database ?
PS: When I create a second edmx in the same project and want to update it, the second one works like it should

After some trials, I found it.
You must delete the connection string in your config file (app.config in my case)

Related

How to update only one table for model from database with Entity Framework?

I have a model generated from db with Entity Framework. When I have any change in database, I update model from database to get the change in model. But this update is applied to all entities (tables) included in model.
Now I add a new column in a table Tab1. I don't want to update model from database as some other changes that I don't want to include in model. I can add the new property in model for entity Tab1 manually. then it caused mapping error.
So I need to update Model.Store for the table to include the new column. It means I want to update model only for Tab1.
How can I do this?
The EDMX file is an XML file that is a combination of 3 different parts that make up the whole thing. If you right-click on your EDMX file and choose "Open with... XML Editor" you'll see the 3 different sections:
<edmx:ConceptualModels>
<edmx:StorageModels>
<edmx:Mappings>
These sections can be edited manually, at your own risk! :-)
That way you can modify only what you need to.
Note that it's also possible to generate CSDL, SSDL & MSL files rather than having them embedded in the binary file, by changing the "Meta Artifact Processing" property of your model to "Copy to Output Directory".
If you don't want to do this manually, there's the Huagati DBML/EDMX tool, it is free and you can download it from huagati official site or from visual studio gallery, which is a Visual Studio plugin that allows you to select what changes need to be done.
I use following (Conditional) trick. This could be done only when no Table depends on the table which you want to update.
Delete the table which needs to be updated.
Right click on Model and select 'Update Model From Database'. The Table would be shown in the tab 'Add'. Select this table and Update the model.
Precaution : If other existing tables have changes in them, EF would update these changes as well.
There is way of doing it automatically.
right click edmx file > update model from data base > Refresh tab > Tables > select the table(you want to update) and press finish that's it.

Entity Framework: deleted SQL table is not removed from the model

Seemingly simple thing got me completely frozen and I can't find anything on the Net about this:
I had a common many to many relationship in my db:
Table One + TableTwo + LinkingTable with 2 columns: TableOneID and TableTwoID
I deleted the LinkingTable and tried to update the model from database. Now I get error "Error 11007: Entity type 'LinkingTable' is not mapped."
Does anyone know what exactly this EF wants? Thank you!
Right-click the Model in the Solution Explorer. Select "Open with..." Select "XML (Text) Editor" in the dialog. Remove all nodes and references of the LinkingTable (or whatever its real name is) from the model's xml. Close all model files that are currently opened (I know, weird). Build the project. Open the model again. Everything should be fine now.
Open Model Browser,
In the Entity types, select the table which is to be deleted,
It will remove all the associations with the table.
It worked well for me.

MVC Entity Type Missing

I'm brand new to ASP.NET MVC (Literally just two days of learning on the fly). I'm trying to create a website using MVC, however, I've screwed something up in my solution.
I created this table that had foreign key constraints but I initially forgot to set up a primary key on the id field and forgot to set it identity specification to yes. So when I updated my DataModel and brought this table in, it showed every field as being the primary key and it showed the relationship to the other tables. So I went back to the database and changed the id field for the table to be the primary key and identity specification to yes.
I went back to the DataModel, tried to Update Model From Database, went to the refresh tab, expanded the tables, and selected the table I wanted to refresh, then click on "Finish".
The data model appeared to make the changes but it showed the relationships to the other tables twice.
So I thought I'd delete the table (entity) from the DataModel diagrahm and bring the table back in through Update Model From Database. But when I went back to the Update Model From Database...
Under the Add tab, the table isn't under the Tables
Under the Refresh tab, the table is listed, but when I select it and click on "Finish" the table doesn't reaapear in the diagrahm.
In the model browser...
Under Models
Entity Types, The entity isn't listed
Under Associations, The relationships no longer appear (obviously because the entity is gone).
Under Models.Store
Tables/Views, The table is listed.
Constraints, the relationships are shown.
I've tried dragging the table over to the diagrahm from the Model Browser, but that doesn't appear to work.
I've tried to right click in the diagrahm, add Entity but my table doesn't appear as a Base Type.
I've tried to google but I'm coming up with nothing. With this entity missing, I cannot even build my solution. Please help.
Try to delete the entity file and add it again. But you have to name it as previous entity and don't forget to delete the connectionString in web.config before add it.
If you don't know what I am saying just let me know.

Entity framework 4 updating the model when a table changes

I am using Entity Framework 4.
I have my model file with my tables on it. If I go and add a new column to one of my tables (in SQL Server) how do I update the table in the model without having to go and delete and re-adding it to the model?
Thanks
There is an option when you right click anywhere in the model (*.edmx): Update Model From Database...
Then a wizard will look for any differences (Add / Refresh / Delete). So if you need to update a table, go to the Refresh tab and select your table.
Mind you, this is only possible in an Entity Framework model, not in a LinqToSql model.

EF4 is throwing an error "Schema specified is not valid"

I'm getting a weird EF4 "Entity Framework v4" error when I do a select on the context:
Schema specified is not valid. Errors:
The relationship 'AnalyzerConfigurationModel.FK_AnalyzerMetadataParameters_AnalyzerMetadata' was not loaded because the type 'AnalyzerConfigurationModel.AnalyzerMetadataParameter' is not available.
The query to generate the error is:
Using context As New AnalyzerConfigurationEntities
Dim EFAnalyzerConfiguration = (From P In context.AnalyzerConfigurations
Where P.Name = analyzerConfigurationName).FirstOrDefault
End Using
The schema is show below.
I've checked the connection strings, multiple times, its not that. Everything looks fine. I'm not sure if the XML that gets generated from this schema is off or not. But looked there too and don't see anything off or different from other properties. Has anyone run into this one before?
I found that if I expanded the EDMX file in solution explorer (VS 2012) and right clicked on each .tt file and selected Run Custom Tool also fixed the issue. This might be easier than de
Also make sure you're referencing project has the EntityFramework installed otherwise the dependent code will get this error.
https://www.nuget.org/packages/EntityFramework
Let me explain this:
The problem is because the system did not find consistency of the columns in database, the entities in the .edmx file and the model class and also the use of the same in the controller class.
So follow the following steps to fix this up:
Go to the database, check all the column names and properties.
Confirm them with the class diagram in the.edmx file. Right-click on the class in which you are getting the error, and select update option for the class. Select the Refresh tab in dialogue (if there is no new column added. if new column is added, you can select the add tab.) and select the relevant objects. Generally they are tables. So select them and finish.
Next check the names in the model class and the controller class.
This should be the solution. If not, let me know.
Are you using the SelfTracking Entity T4 template? I had this issue and found out the T4 template was not re-generating my entities after I had changed the Entity model in the Entity Designer. Try to right click the T4 Template and click "Run custom tool", and see if that helps.