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.
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
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.
I was building a DataAccessLayer using C# in VS 2012, and in my project, there are three files which I don't know how to deal with.
DataAccessLayer.csproj.mine
DataAccessLayer.csproj.r60
DataAccessLayer.csproj.r72
What are they? How should I deal with them?
They are files created from your repository that the code is saved in. You did an update and when you try to commit your files you will get a commit failed probably. When you diff the files, it will use the .mine .r60 .r72 files to bring up the differences between each revision (.r60, r72) and your file (.mine) and allow you to do something like Keep all changes in mine.
In order to get rid of the commit failed error messages, find the original file, update it with the correct changes, and when finished right click it and Mark as resolved and commit. This will get rid of those files.
Those files are related to version control (.mine is your file, .rX come from revision number X). You should try to merge them using your version controlling tool if you have one. If you don't have one and got those files by copying a project, you can possibly delete the .r files and rename DataAccessLayer.csproj.mine in DataAccessLayer.csproj (unless you already have DataAccessLayer.csproj - just keep it and delete the other then). Edit: And if it causes problems, try merging them manually (using a text editor for example) before keeping the final file.
In my project, I have a data-access layer that contains .dbml file(named test.dbml) used to drag and drop stored procedures and tables. Two days ago when I drag and drop the stored procedure onto my test.dbml file. Upon saving it creates another test.designer1.cs class and the old test.designer.cs class remains unchanged. I use visual studio 2010 and it was very weird for me. I've checked my rights on the folder which contains my project but all seems ok because two days earlier it was working fine and suddenly it happened. I Google it but find no solution so I decided to write this question.
At-last i've solved it myself.........and i am going to share it that what i have done. my dbml file name was test.dbml having test.dbml.layout and test.designer.cs files now the problem was when ever i drag and drop stored procedure or table it creates a new designer file with name test.desginer1.cs and when i build data-ccess layer it gives me hell of errors my brain was out at that time and with angry face i delete the test.designer.cs (original file) from the solution after that there was only one file test.designer1.cs which i renamed from test.designer1.cs to test.designer.cs and build data-access layer and i was wondered that it was build successfully. this solve my problem however there are other points as well to keep in mind
make sure your dbml files should not be read-only
you have full access to write file on disk (means check your rights on directory where your solution is placed)