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.
Related
I connect to Sybase IQ database via PhpStorm. End I have a tables explorer at database tool window.
What I need is to make tables names display like schema_name.table_name, not just the table name. Seems like I can achieve it in database driver settings, but don't know what should I do exactly. There is a setting in database connection window where I can choose such setting in AquaData studio.
AFAIK it's not possible to have schema_name.table_name -- only db_name.schema_name.table_name.
For this just enable "Flatten Schemas" option (under "cog" icon or via right click on tool window title/label).
P.S.
Cannot say anything about database driver settings for Sybase.
Usually connect to an external database but I wanted to fiddle with creating a project with a local database. I am using SQLServer Express Local Database, not CE.
I can add tables with EF but if I right click on Tables in Server Explorer the only options I have are Refresh and Properties, i.e. no Add Table menu option. Similarly, if I right click on one of the tables EF has created I also get only the Refresh and Properties menu options so I can't add rows, etc. Same problem with stored procedures; I can't add any (should I want to do some testing with EF and stored procedures) because I only have the Refresh and Properties menu options.
FOLLOW UP:
I have isolated this problem to VS2012 Professional. When I use VS2010 it works exactly as expected: I can add tables and stored procedures. Following the same steps with VS2012 results in the situation where there is no menu option to add either tables or stored procedures. I produced these test results with SQLServer 2012 LocalDB.
If you only see Refresh and Properties when you right click on Tables in Server Explorer, you probably need to install SQL Server Data Tools from http://msdn.microsoft.com/en-us/data/hh297027 .
I had a similar problem only with Visual Studio 2012 Express for Web following along with the "Getting started with ASP.Net MVC3" at www.asp.net. The tutorial used a Sql Server Compact edition but I have SQL Express 2012 so I changed the connection string to have the data source point at my local instance, .\SQLExpress2012. The app worked fine and was able to read and write to the database. However I could not edit the database in the Visual Studio Express Database Explorer (all the context menu options were missing except "refresh" and "properties).
I found that changing the data source in the connection string to "Data Source=(LocalDB)\v11.0;" fixed the problem. I read somewhere that if you use LocalDb instead of the SQL Server instance name then it will be accessed under your user account - must have been some kind of permissions issue.
The whole (working) connnection string is:
"Data Source=(LocalDB)\v11.0;AttachDBFilename=|DataDirectory|Movies.mdf;Integrated Security=True;"
Hope this saves someone a bunch of hours pulling their hair out, I'm almost bald now :)
I found that when installing Visual Studio 2013, I had not requested the 'SQL Server Data Tools' feature.
By re-running the installer from 'Control Panel' > 'Programs and Features', using the 'Modify' option, I could add the missing feature. On completion, the 'Add New Table' menu item was available.
I watched a video in relations to creating and working with databases in Delphi. The video states that you can create the database using code, the data explorer or the SQLite3 console application, but I am unable to find out how to create the database using the Data Explorer. Does anyone know a way I can go about doing this?
Thank you in advanced.
The instructions that follow are for XE3, but they should work for XE as well.
Right-click on the SQLite item in the Data Explorer, and choose New connection.
Enter the full path to your new database file (which, of course, won't exist yet) in the Database edit control.
Click the Advanced button in the lower right corner of the dialog. Find the entry for FailIfMissing, and change the value from True to False, and then click the OK button to close the Advanced Properties dialog.
Click the Test connection button in the lower left corner of the dialog (directly across from the Advanced button you clicked before). You should get a dialog that says Test connection successful. Close the New Connection dialog. (If you don't get a successful test connection at this point, check the path to the database you entered; it will fail if the folder doesn't exist. It can also fail if the SQLite3.dll isn't on your Windows PATH or is the wrong version.)
To create tables, expand the Data Explorer entry for your new connection created above, so you can see the Tables, Views, and Procedures branches. Right-click on Tables, and choose New table from the pop-up menu.
The only way I can determine in VS 2012 to open an existing stored procedure for modification and save changes is the following:
1) Manually remove the initial word CREATE and retype ALTER in its place (every time).
2) From the "SQL" menu, then its "Transact-SQL Editor" submenu, choose Execute.
Given that VS2012 is in Release Candidate, I'm certain there will be no fundamental changes along these lines.
And, I understand that from a purist point of view that this is executing a query to change the procedure on the server. But from a usability point of view is there no longer a near-equivalent to a simple Save button on a toolbar? Over the course of day this is a not-inconsequential waste of time and mental focus. I could live with Ctrl+Shift+E but manually editing CREATE to ALTER every time is ridiculous.
I take it that you're trying to apply changes to a stored procedure to your database?
You can try the following:
Go to View SQL Server Object Explorer. Right click on the SQL Server node and add your server. Open the database and identify the procedure you need to edit. Double click on the procedure, which opens the CREATE script for the object. Leave the CREATE there and simply modify this and click the 'Update' button. Then select Generate Script or Update database depending on whether you want to apply the changes immediately or generate the script to a query window and apply the script yourself.
If you want to generate an ALTER, you can use the Server Explorer (as distinct from the SQL Server Object Explorer, which is also in the View menu). Add your database to Data Connections. Find your procedure, right click and select Open.
I'm fairly certain you can add the procedure to source control, make changes, check in, and publish to your DB. I've never done it, but its talked about in this video:
SSDT talk at TechEd 2012
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.