Why is my edmx file not updating - c#

I have a database first ASP.NET MVC 5 EF6 project. I'm using VS2015 CE. When I change my database (SQL Server 2012), I then go to VS to update my edmx file like this:
Double click on the edmx file in the solution explorer
In the edmx file right click on a blank space and select the option 'Update Model From Database'
I click on the button 'Finish'
I Rebuild the solution
When I have a table with the columns ID, Column1, Column2 and I changed Column2 into Column2Changed, my edmx has a model with ID, Column1, Column2, Column2Changed instead of ID, Column1, Column2Changed.
Also, when I change the datatype for a column, this change is not applied in my edmx.

This is a well-known problem with Entity Framework.
"Update Model from Database" continues to be a hit-and-miss affair. Sometimes it works, often it doesn't.
Personally, I just delete the "updated" table from my .edmx file, then re-add it. Then it seems to be work okay.

This worked for me :
1.Build the project after updating EDMX file.
2.Right click your .tt file in solution explorer.
3.Select "Run Custom Tool" option.
This will update the .tt file.

Make sure that you selecting the objects from Update tab

When faced with this issue, i solved my by change the username and password...so i would say, make sure you have a valid connection string in your edmx

I've had this issue on a number of occasions. For simple problems I've edited the edmx file by opening in the code editor ( Open With... > Source Code (Text) Editor ).
Locate the table by looking for by searching for EntityType Name="your table name".
Typically I see an entry that doesn't look right, delete it, save and close the file. Open the edmx the usual way and refresh the model and Presto problem solved.

After updating or refreshing and not getting expected results.
I worked as follows:
1. I added procedure without importing it.
2. I opened edmx with text editor and added my return types having complex type like other already present in it.
3. added all values like other procedures had.
That solved my problem!

Maybe it's not logical but when We add empty table to Edmx, it is not added. If Adding a table with some records, will fix the problem.
Fix: Allways when an error occurred, when you open edmx in notepad, errors shows, maybe you dont have primary key and so on.

What worked for me:
I updated the edmx model and then clicked Save button in edmx designer.
It seems like the code for all modified entities (views, tables, etc) is regenerated only on Save.

I faced the same issue. The most reasonable solution could be to delete .edmx file and to regenrate it. Keep in mind that you should always try to update model first if nothing work then do what I just said.

Related

How to rewrite the Delete and Update methods based on new DataSet binding?

I have added a new column to my DataSet and after adding, visual studio asked me if I want to rewrite my updating methods and I said yes. Now, My Delete method is broken and I can not use it like before. What should I do ?
Amirhesam
You have to manually configure your Delete method like below
Table Adapter Properties -> Delete Command -> CommandText
enter image description here
You should be using source control then diffing to see what it changed the delete to imo. Should be trivial to manually fix whatever the VS autogen did to bollocks it up.

Entity Framework and TFS - Code check-in after deleting entities from edmx and adding back again

I had to change the datatype of a column in my database, after changing it I have deleted 2 tables in my edmx and saved it, then added back those 2 tables again using update model from database option and saved it.
I have then right clicked on model.tt and model.context.tt files and selected run custom tool, the application built successfully after these steps.
Now I want to checkin this code, when i clicked checkin in the changes window it shows that the Employee.cs and Department.cs files as deleted with horizontal line on those files, below it shows detected 2 adds and it shows Employee.cs and Department.cs files and when I selected promote it it is giving the below error.
/xyx/test/myapplication/myapplication.datamodel/UserRegistration/Employee.cs already has pending changes.
The same error is shown for both the Employee.cs and Department.cs files.
Any help on how to proceed from here ?
Two options:
Treat the delete and the add/edit as individual check-ins. Delete the tables, regenerate the models, check-in the delete. Then re-add the tables, regenerate the models, check in the new files.
Treat the regeneration as a single action. Use the undo-pending changes to get rid of the pending delete. Regenerate the models. Check in the changed files.

visual studio randomly updates designer.cs file for my dbml

I have a linq-to-sql connection for my database. I added a new table to the db in SQL server management studio today. Since it doesn't get automatically added in the dbml file, I dragged and dropped the table from server explorer as visual studio suggests.
This automatically makes the necessary changes to its designer.cs file, which is good.
Unfortunately, it also makes some other changes I didn't ask for. There are a bunch of variables getting renamed in the designer file consistently, which has nothing to do with the table I'm adding or the one it's connected to!
I am being very careful not to move any other table in that layout- I'm just doing a drag 'n drop in an empty area. I tried this multiple times with the same result, so maybe I'm doing something wrong. I searched everywhere and I can't seem to find a better way to update the dbml file for tables added ( I found a bunch of questions about updating the dbml file when columns are added to existing tables, unfortunately those answers don't apply here).
Has anyone ran into this issue before? Is there any solution to this?
The solution is to ignore it. The entire purpose of designer files is that they are tool-generated and may be regenerated at any time, for any reason, with any number of changes.
Under no circumstances should you modify them, and there's usually not much of a reason to look at them.
I had to fix it the hard way- manually updating the variable names by looking at the diff of the designer file. It was not fun, but it got rid of all the errors.
Apparently, it was renaming a bunch of associations for some other table consistently. Turns out someone had renamed those associations in the designer file instead of the .dbml file. So every time any change is made to the .dbml file, the designer file recompiles, and old names come back! I should probably update those associations in the dbml file so we don't have this problem in future.

Updating EF6 edmx model causes new model file to be created

I'm using EF 6.1 with the downloaded T4 template from VS. When I try to update the EF model with new information, or just issue a refresh from my database, the model file duplicates and I get a massive amount of errors.
So, for example, my model file is called Test.edmx, which has subfiles called Test.Designer.vb and TestModel.tt. The TestModel.tt has a subfile called TestModel.vb which appears to contain all my entity framework models.
When I right click on the design surface and select "update model from database", and either add a new entity or refresh an existing one, instead of updating the TestModel.vb file, it creates a whole new file called TestModel1.vb. Once that happens I get thousands of duplicate item exceptions, because now there a doubles.
Why is this happening, and how can I fix it? Is something configured wrong? This model was previously using EF4 and was upgraded straight to 6 using these instructions. https://msdn.microsoft.com/en-us/data/upgradeef6.aspx
It sounds like the linkage between your model/tt file and the output file has been broken. You could open the project (vbproj) file in a text editor and look for test.edmx or testmodel.tt. You should find one or both of them inside nodes somewhere. The file in the enclosing node is the one that depends upon them. At a guess you'll find this is currently TestModel1.vb. You could try editing this and reopening the project, but the simplest thing might be to exclude your existing TestModel.vb and let visual studio have its way. It should be a hidden file after all

Losing database update after changes in code

I have a simple question. I'm new to .net and sql and I'm trying to write a small form application. I added a data source which I created in sql. I got textboxes, button to update tables in database. When I made changes in database, like adding or deleting rows from tables, these updates are getting lost if I made a little change in application code (for example entering a new line).
Probably I'm unaware of something simple. What is the cause of it?
Select the database from solution explorer, go to properties (or alt + enter) and change the Copy to Output Directory to Copy if newer (copy if you change the database) or Do not copy. If the selected option is Copy always, the database is copied each time the project is build.

Categories