Entity Framework removes files from Source Control - entity-framework

we're using Visual Studio 2013 Update 4 with Entity Framework 6.0.2.
Our process for adding new tables, and new pocos is described in these steps:
Define new tables in the database project.
Publish the database to localdb server
Open EDMX-Designer and right click somewhere in the designer and select "Update Model from Database..."
Save the EDMX
The Code-Generator re-creates all pocos under the edmx-name.tt file inside of the edmx-name.edmx container.
In most of the cases everything works fine! In some cases the code-generator removes certain files from the source control. Most of the files existed already before the "Update from Database..." process, and were already under source control. I have to right-click the edmx-name.tt file and select "Add files to source control" to fix this.
This is a nightmare for the development process in the team! If it would happen always, I would always check the pocos by myself before checking in. But it is totally random, I can not see a reason why this is happening.
Is anyone experiencing problems like that? How can we fix that?
(I have had problems like that with other Versions of EF, too)

You should not have generated files under source control. If you remove them, but keep your entity model, them this will not be an issue.

Related

Adding a new Entity Framework shows warning and no wizard is displayed

Every time I want to add an Entity Data Model using "EF 6.x DbContext Generator" to my VB.Net project, this warning appears instead of "Entity Data Model Wizard":
Running this text template can potentially harm your computer.Do not run it , if u obtained it from an untrusted source
Click OK to run the template
Click Cancel to stop the process
And when I click OK no wizard is showing. just two .tt file are added to the project. These .tt files are opened as text files.
I tried this with several new projects and this error happens everytime.
I have Microsoft Visual Studio Enterprise 2017. Version 15.7.6
The correct way of adding a new Entity Framework Model using the "Entity Data Model Wizard" is selecting ADO.NET Entity Data Model in the "Add New Item" window instead of EF 6.x DbContext Generator.
But that warning will still show sometimes.
go to path:
Tools > Options-> Text Templating ->Show Security Message set False

How to create ADO.Net Entity Data Model (.edmx) without opening diagram

I'm working on Database-first Entity data model. Due to nature of project there are lots of entities and I've a single .edmx file for that.
Every time I've to regenerate edmx file it takes a lot of time and some amount of time is consumed in loading the diagram in Visual Studio (2015). I don't want Visual Studio to open the diagram automatically as its not useful to me.
Is there any way to regenerate the edmx file without automatically loading diagram in Visual Studio?
I've checked on various sources but couldn't find any way to do it.
To regenerate, right click on the edmx file and select "Run Custom Tool"
To stop loading the Diagram:
Right-click on the edmx file and click "Open With..."
Then select "Source Code (Text) Editor and then click "Set as Default".
You can change it back to the "ADO.NET Entity Data Model Designer" at a later date by performing the same process.

Adding multiple oracle schemas in visual studio 2013 and EF

I have a serious problem that needs to be resolved.
In my server explorer in VS2013, I set up a connection to the database with valid user and password credentials.
So I have a schema called: Connect1, and it needs to have access to another schema called Connect2, both under the same data source name: Dev1. The user I'm connecting with is called Connect1, so by default I'm connected to the schema Connect1. I was able to verify that I have access permissions for this user to connect to Connect2.
Using ODP.NET Managed Driver, I was able to set this up. Putting all the connection details.
Configurations are shown in this page:
Using Oracle Developer Tools for Visual Studio
In order to allow the schemas to be viewed, I had to change the Filters tab, and add all the related schemas I'm using (adding Connect2). Then I click update, and I'm able to use the tables into my edmx file.
However, the problem occurs when I close Visual Studios. My filter gets lost, and my connection is back to using only Connect1.
This then destroys my table mapping in my edmx file with a series of
Error 11007: Entity type 'Table1' is not mapped
This is really frustrating as I'd have to keep on repeating the same procedure over and over again manually remapping all my tables.
What's confusing is when I update the data connection from my Server Explorer to include the second schema.. EF works and detects the tables; but my app config and the connection string has not been changed. So this leads me to believe that if I was to promote my project to production or test, that it will break since there's nothing in my project to show that Connect2 is needed.
Okay I realize the big pitfall that was never explained properly. I highly urge people to follow this if you ever want to use EF with Oracle and you're using another schema.
The pitfall is that since we introduced oracle's schema convention to the EDMX, there was no way of knowing how volatile the mappings would become. The reason why this was never a problem for microsoft is because there is no such thing as a schema in SQL server. To implement two databases in the same edmx file, there is some visible prevention that inhibits you from adding any tables whatsoever. After we introduce schemas, it becomes very fragile.
So what you have to do is follow the steps of adding the schema (as I explained in the question). Going to Filter tab, adding the schemas that way, and clicking the Update button.
Once that is applied to the server explorer, the edmx will have access to adding the tables from that schema. When you do, the EDMX has recollection of the schema embedded in its file. So if you ever do close visual studios, and reopen and run the project, it will still work.
Here are the few tips you want to AVOID:
Do not rename any of the entities and the columns (properties), even though it makes your code more readable. That's the first uh-oh. Since the mappings are very volatile, if you happen to mess up, remapping everything back again will be a chore.
The second uh-oh, is when you close Visual Studios, reopen it again, forget to reinclude your schema in Server Explorer, go to the edmx and do "Update model from database" to include anything else (but most importantly.. EVEN IF YOU DON'T DO ANYTHING) and you click OK, your model will still update regardless of non-changes, lose all the mappings that you previously made. That is what I mean by the maps being volatile.
In case that happens, and you didn't do the first uh-oh of renaming entities or the properties.. is to delete all your entities already there, and re-add them again.
The reason why you want to delete all the entities is because adding new ones with the same name will add a new entity with the same name + a number. So something like entity of Customer will still be there, adding the entity again will create a new entity called Customer1.
Sigh.

Entity Designer missing

As the title says, somehow the entity designer disappeared from my installation of Visual Studio 2010.
When trying to open an .edmx file, it only opens it in the XML editor. When i choose "Open With...", the Entity designer doesn't show up in the list.
It has worked before, and i don't know of anything i could have done to remove it from the list. Does anyone know how i can re-add it? Thanks!
First thing to check is, is this a problem with your project or with your VS installation.
Try creating a new project and see if the entity designer is in the list
If it is you have two options
Move your files to the new project
Try to repair your project file
The way it works is that there are a set og Guids in the project file that control what is available in that project. So you can open the project files in notepad, find out which is missing and then move them over.

Entity Framework : How do you refresh the model when the db changes?

If you build the edmx file from the database and then the db changes, how do you get the model to pick up the change?
Do you delete the whole model and regenerate or can you detect changes?
I see a post mentioning a "Update Your Model" rt. mouse command on the edmx file, but I dont see it.
Updating your edmx to reflect changes made in your db (.net linq-to-entities)
I'm just starting out.
Are you looking at the designer or code view? You can force the designer to open by right clicking on your EDMX file and selecting Open With -> ADO.NET Entity Data Model Designer
Right click on the designer surface of the EDMX designer and click Update Model From Database...
All entities are refreshed by default, new entities are only added if you select them.
EDIT:
If it is not refreshing well.
Select all the tables and view-s in the EDMX designer.
Delete them.
Then, update model from database
I have found the designer "update from database" can only handle small changes. If you have deleted tables, changed foreign keys or (gasp) changed the signature of a stored procedure with a function mapping, you will eventually get to such a messed up state you will have to either delete all the entities and "add from database" or simply delete the edmx resource and start over.
This might help you guys.(I've applied this to my Projects)
Here's the 3 easy steps.
Go to your Solution Explorer. Look for .edmx file (Usually found on root level)
Open that .edmx file, a Model Diagram window appears. Right click anywhere on that window and select "Update Model from Database". An Update Wizard window appears. Click Finish to update your model.
Save that .edmx file.
That's it. It will sync/refresh your Model base on the changes on your database.
For detailed instructions. Please visit the link below.
EF Database First with ASP.NET MVC: Changing the Database and updating its model.
Update CodeFirst Model is not possible automatically. I don't recommend either.
Because one of the benefits of code first is you can work with POCO classes. If you changed this POCO classes you don't want some auto generated code to destroy your work.
But you can create some template solution add your updated/added entity to the new model. then collect and move your new cs file to your working project.
this way you will not have a conflict if it is a new entity you can simply adding related cs file to the existing project. if it is an update just add a new property from the file.
If you just adding some couple of columns to one or two of your tables you can manually add them to your POCO class you don't need any extra works and that is the beauty of Working with Code-First and POCO classes.
Here:
Delete the Tables from the EDMX designer
Rebuild Project/SLN (this will clear the model class)
Update Model from Database(readd all the tables you want)
Rebuild project/SLN (this will recreate your model class including the new columns)
You need to be careful though,
You need to setup the EDMX file exactly as it was before deleting it (if you choose the delete/regenerate route), otherwise, you'll have a naming mismatch between your code and the EF generated model (especialy for pluralization and singularization)
Hope this will prevent you some headaches =)
Double click on the .edmx file then right_click anywhere on the screen and choose "Update Modle From DB".
In the new window go to the "Refresh" tab and choose the changed table/view and click Finish.
I just had to update an .edmx model. The model/Run Custom Tool option was not refreshing the fields for me, but once I had the graphical designer open, I was able to manually rename the fields.
I've been working on a project, not too large, that incorporates Entity Framework, about a dozen tables, and about 15 stored procs and functions. After weeks of development, attempting to refresh my tables and stored procs has yielded mixed results as far as successfully updating the model. Sometimes the changes are effective, most times they are not. Simple column changes (changing order, adding, removing, or renaming) sometimes works, most times does not. Visual Studio seems to have more problems with refreshing than just adding new. It also exhibits more problems with stored proc changes not being reflected, especially when columns are added or deleted or renamed. I have not detected any consistent behavior so i can't say "This type of change will always be updated and this type of change will not".
End result, if you want 100% effective solution, delete the EDMX file from the project, "Add new" item to project (ADO.NET Entity Data Model), and make sure you use the same name for the Model Name. This works every time.