I'm working on updating an old system, and we're introducing Entity Framework for some new functionality. The system is, however, too large to do the migration in one step, so I would like to do some testing in another database before updating the db schema.
I have created an empty model, included a couple of tables from the database, and added a couple of new entities from scratch, along with relationships between these entities and the old tables. Now I want to create a new database schema in another database with my desing model, but I can't figure out how to switch so that clicking "Update database from model..." won't work with the old database, but the with the new one.
Is there a straight-forward way to do this?
In short, the connection settings are in your config file or a Data Connection. Entity Framework Connections and Models provides official documentation.
If your connection settings are in your config file, i.e. Web.config / App.config, you can change them there (additional documentation available in Entity Framework Config File Settings). If you used EF Designer to create your model, the option to save settings in the config file was in the Choose Your Data Connection Dialog Box (Generate Database Wizard).
If your connection settings aren't in a config file, they live in the Data Connection in the Server Explorer in Visual Studio: View > Server Explorer; expand Data Connections, right-click on the connection and choose Modify Connection.
Related
I am really sorry to ask a simple question like this, but it is getting frustrating. I installed neo4j 4.0.4 on my Windows machine, created a new project as shown in the official tutorial video and set a password for my local graph. Funnily, the tutorial video ends after setting the password and opening the browser not showing how to perform Cypher queries on this newly created database. In neo4j Desktop my database is shown correctly and it seems to be up and running.
However, when I try to connect to this database via the browser, I do not see the database at all. It is so confusing when connecting to the server to specify a username and password, if you only need to set a password for your database?! The default neo4j user can see the system and default database but not my project database. In addition, I cannot link files from the project directory in Cypher queries. I tried to disable authentication, but it did not help at all.
When I issue SHOW DATABASES command, it does not list my database as well.
Update / Edit:
Seems I misunderstood the concept of projects. Every database is named neo4j - default, regardless of the name specified in the project ?!. However, I still cannot access project files. So far, I copied the files manually in the database directory under "imports". But I guess that is not the intended way.
After importing data to this default database, it still shows no data in the project itself.
Data files in the imports directory are not automatically imported into the DB. That is because neo4j has no idea how you want to store that data as nodes and relationships.
So, it is up to you to determine your desired data model, and then write the appropriate code to enforce that data model.
You can take a look at this page to learn about how to import CSV data (probably the most commonly used import data format).
I am new to MVC application. When I tried to create the Model I wanted to find "Generate from database" option as follow.
But I have following options.
Which option I can select instead "Generate from database" option.
Right-click the Models folder, and select Add and New Item.
In the Add New Item window, select Data in the left pane and ADO.NET Entity Data Model from the options in the center pane. Name the new model file.
Click Add.
In the Entity Data Model Wizard, select EF Designer from database.
Click Next.
If you have database connections defined within your development environment, you may see one of these connections pre-selected. However, if you want to create a new connection. Click the New Connection button.
In the Connection Properties window, provide the name of the local server where your database was created or you sql server name. After providing the server name, select your database from the available databases.
Click OK.
The correct connection properties are now displayed. You can use the default name for connection in the Web.Config file
Click Next.
Select Tables to generate models for the needed tables.
Click Finish.
For the full tutorial on Microsoft website
https://www.asp.net/mvc/overview/getting-started/database-first-development/creating-the-web-application
If you want to create entity classes, then choose the "EF Designer from database", then follow below:
New connection.
Change.
Microsoft sql server.
insert your SQL server name + SQL credential
Chose your database.
Test connection, if you got it right press k.
Next > Next.
Then choose the table you would like to generate.
I created the databases first, then used the wizards in Entity Framework 5 to create the models from the Database first. Over time, through development, I made changes to the models and let EF recreate them by deleting my database and then starting the project up and they magically appeared again with the changes I made to the columns . It worked great on SQL Express 2014. But Godaddy doesnt let EF do that, AND I have databases with names like "Hazards.Models.CompanyDataContext" that EF made and didnt ask me what I wanted to name them. How do I change the code so it will let me rename the database it uses, and if possible, incorporate it into the aspnetdb that mvc uses as an additional table (there already is simplemembership etc. in there.)?
Seeing as you used EF database first, rather than deleting your database and letting EF recreate it, have you thought about doing it the other way round?
You could use something like management studio express to rename your database tables/columns however you see fit. Then in Visual Studio, open your .edmx file, right-click the background and select 'update model from database'. This way you can add new tables to the model or update the models of existing tables from the database. Better still, you can take care of it all outside of godaddy.
Note: I found that when updating the EF model, just updating existing tables gives odd results sometimes. It's much more reliable when you delete tables from your .edmx first, then right-click and select 'update model from database', and add the tables back to your model.
I am an application with an EDMX file. My connection to this edmx is different in stage from the development environment. i wanted to change the connection string of edmx file while moving application to stage environment.
I tried removing the edmx and creating a new edmx with the stage environment. edmx is getting created fine. But the edmx entity class is not getting referred in the code i.e it's not even showing in the intellisence.
Is there a way to change the connection string directly instead of deleting and adding edmx?
If yes, please post that how we can achieve.
Thanks,
venugopal
was wondering if it's possible to point the visual web express to a specific folder when it builds the database using entity framework code first. this question stemmed from this one:
mvc connection string code first
anyway, i was able to successfully build the dbase using code first but sql server management studio is looking at a diff folder. is it possible to piont the web express to that folder when creating the database or is it better to just point the sql server management studio to where it's building it to? (does that make sense?) i tried fiddling with the ssms properties but it still won't look at that folder..
It whole depends on the connection string. If you are using default connection string for web application it always creates database in App_Data folder - it is specified by AttachDbFilename=|DataDirectory|DatabaseFileName.mdf. Using this is recommended way if you want your web app to create database because it should have necessary privileges by default.
If you want to place the database "elsewhere" you should not use attached db file and instead let SQL server create database in its default location by calling omitting AttachDbFilename part of the connection string. This can require additional security configuration to allow web application to create the database.