Generate "M" from an Existing Database
[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]
This is the sixth and final step in the Getting Started with SQL Server Modeling CTP and Visual Studio 2010 tutorial. The preceding step is Add a Main Web Page to the Application.
Generating “M” from a database
Create a new database with the following script.
set xact_abort on; go create database MiniNerdDinnerData go begin transaction; go use MiniNerdDinnerData go set ansi_nulls on; go if not exists ( select * from [sys].[schemas] where [name] = N'MiniNerdDinner' ) execute [sp_executesql] N'create schema [MiniNerdDinner]'; go create table [MiniNerdDinner].[Dinners] ( [Title] nvarchar(max) not null, [EventDate] date not null, [Description] nvarchar(max) not null, [HostedBy] nvarchar(max) not null, [ContactPhone] nvarchar(max) not null, [Address] nvarchar(max) not null, [Country] nvarchar(max) not null, [Latitude] decimal(28,6) not null, [Longitude] decimal(28,6) not null ); go insert into [MiniNerdDinner].[Dinners] ([Title], [EventDate], [Description], [HostedBy], [ContactPhone], [Address], [Country], [Latitude], [Longitude]) values (N'Geek Out', '2009-12-06', N'All things geek allowed', N'Darren Parker', N'425-555-1212', N'One Microsoft Way, Redmond, WA 98052', N'USA', 47.64312, 122.130609), (N'Fine Wine', '2009-12-07', N'Sample some fine Washington wine', N'Charlie Herb', N'425-555-1212', N'One Microsoft Way, Redmond, WA 98052', N'USA', 47.64312, 122.21201), (N'Surfing Lessons', '2009-12-08', N'Ride the waves with Rob', N'Rob Walters', N'425-555-1212', N'One Microsoft Way, Redmond, WA 98052', N'USA', 47.64312, 122.21201), (N'Curing Polio', '2009-12-09', N'Discuss how we can eradicate polio', N'Bill Malone', N'425-555-1212', N'One Microsoft Way, Redmond, WA 98052', N'USA', 47.64312, 122.21201); go commit transaction; go
In Solution Explorer, right-click the Models folder, click Add, and then click New Item.
On the Data tab, select M Model Data. Type
DinnerData.m
for the name, and then click Add.In the Entity Data Model Wizard, select Generate from database and click Finish.
In the Connection Properties dialog, connect to the
MiniNerdDinnerData
database as shown below:A new
DinnersData.m
file that contains additional data instances will appear in the project.Re-deploy to the database and run the application by pressing F5. For more information, see Deploy Domains to the Database.
Navigate to the main screen. The row data from the database will appear as shown below.
See Also
Concepts
Getting Started with SQL Server Modeling CTP and Visual Studio 2010