The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








I heart FeedBurner

Latest Diggs - Programming

Computers Blogs - Blog Top Sites

Site Hits

Total: 4,868,426
since: 19 Jan 2005

Tour of Oslo: Storing Models in the Repository

posted Tue 28 Apr 09

In my last blog post on Oslo , I walked through a simple scenario where we created an "M" file that contained the models for a fictitious science fiction game. We used this file and IntelliPad to see what the T-SQL might look like if we were to create just the tables defined by the model. In this blog post, I'm going to walk through the process of taking an "M" model, compiling it into an MX image, and finally storing that image in the repository.

If you're following along, you can grab the "M" file that I created in the previous blog post or you can create your own. The repository is a central storage location for models. Not only does it contain the actual schemas generated by your model image, but it also contains a lot more like security and versioning information. In the interest of keeping this post as small as possible I won't go into too much detail, but you can find tons of Repository-related videos over on the Oslo Developer Center .

The first thing we need to do is compile our model. To do that, we'll use the command-line tool that ships with the CTP called m.exe. This tool can be used to generate regular T-SQL, repository SQL, and of interest to us: a repository image of the model. Sticking with the M file I created last time, I can open up a command prompt, make sure the Oslo SDK "bin" directory is in my path and issue the following command:

m UlyssesAgenda.m /p:image

The output is a file named UlyssesAgenda.mx. This is a compiled M file. Now we need to get the compiled M image into the repository. Using this CTP we can accomplish that from the command-line as well using the MX utility:

mx -i:UlyssesAgenda.mx -d:Repository -s:kev-win7\SQLEXPRESS

Depending on your configuraiton, you may not need the "-s" command line switch to indicate the server where the Repository database is stored. In my case, I have a full-blown installation of SQL Server 2008 and SQLEXPRESS is not my default instance so I've found that every now and then that means I have to modify connection strings or, in this case, pass the server/instance explicitly.

And now we can look at SQL Manager and we see that all of the tables that correspond to our high-level model were created:

Using the MX command-line tool we can also directly query the repository. I thought it worth showing the output of this because it illustrates one of the more valuable aspects of Oslo - model versioning:

>mx -l -d:Repository -s:kev-win7\SQLEXPRESS

Microsoft (R) code name "M" Command-line Utility version 1.0.1308.1
Copyright (C) Microsoft Corporation. All rights reserved.

Contents of the database
============================================================

Models.mx                 Models.mx;Version=1.0;Locale=neutral
UlyssesAgenda             UlyssesAgenda;Version=1.0;Locale=neutral

Models.mx is the compiled list of all of the stock models that Microsoft has provided and put into the database as part of the core Oslo offering. What I think is really important to keep track of is that the models themselves are versioned. There are no table versions - the versioning takes place at the model level which is, IMHO, where it should be. Also keep in mind that because at the lowest level we've also created a standard SQL schema, you can use any tool you like against this server, including LINQ to SQL or ADO.NET or the Entity Framework. 

So now we've created a model and put it in the repository. In upcoming blog posts, I'm going to cover some of the other interesting things that you can do with models.

tags:      

links: digg this    del.icio.us    technorati    reddit

AddThis Social Bookmark Button




1. Jamie left...
Tue 28 Apr 09 9:21 am

rake db:migrate. :). Again I'm not saying it's the -same- thing and this is probably much more generalized for many platforms. Aside from SQL server, what other kinds of repositories can mc write a model to.


2. Kevin Hoffman left...
Tue 28 Apr 09 9:31 am

Jamie, obviously you're a Ruby/Rails person... But you'll notice that I never once mentioned anything about _web_ applications in this blog post. I was able to take a model and store it in a versioned repository. Even Ruby doesn't version a model repository... It's up to you to manipulate your migration scripts with sequence numbers so that you can tear down and build up changes in your database. This is better than that - I can version the entire model at the "M" level (which is a very easy to read syntax, and can be visually designed as well). Rake migrations are specifically for RoR websites and aren't really capable of being used anywhere else (yes I know you _can_... but why would you???). The entire purpose behind these series of blog posts is twofold : 1) so that I can learn more about Oslo by doing blog posts about Oslo, 2) so that people can see that Microsoft is taking the modeling problem seriously and coming up with solutions to allow people who build huge-ass data-heavy applications to go with the model-driven development pattern without having the lack of tooling and the other frustrations make people give up.


3. jamie left...
Tue 28 Apr 09 12:40 pm

I haven't really done rails in a long time, not seriously, and I don't think we have any disagreement.

My point is sorta, "How is this any better conceptually?" This technology platform just seems like things we've seen other places, just with a different name and slightly different semantic. If I weren't a developer on the Microsoft stack, and I'm not, what about Oslo would draw me to it? LINQ is something genuinely new and interesting, something you don't see in other platforms. What is the "LINQ" of Oslo?

I eagerly await the article on mgrammar... I appreciate that MS is taking data modeling seriously, but I'm sorta looking for them to take it to the next step. On the other hand, I guess you never really claimed it was particularly innovative from the coder's standpoint, aside from that it would allow different stakeholders to communicate in a common entity language, but as you yourself admit, we have UML for that. M just removes the step of translating UML into the DSL of the database stack you're using, and it allows you to express migrations.

Let me put it this way: I can do an actor use case graph of what happens when a client wants a schema change on their website. How does the Oslo actor graph of this operation differ from the Rails one? Or on the desktop, I have an app with a core data store and schema that saves documents on the user's hard drive- if the users want me to change the schema, there's a set of steps I take, ending with the users happily using the new app version. How does Oslo change this?


4. Pieter left...
Tue 28 Apr 09 1:01 pm

So how is this part different from having a special table with blob/text containing the model file and a kind of wrapper loading this version of the file into the SQL database table definition?

Up till now it seems to me that this Oslo is just a sort of Forms GUI for MS SQL?


5. jamie left...
Tue 28 Apr 09 5:05 pm

Pieter- I found these, it's very interesting...

http://msdn.microsoft.com/en-us/library/dd219521.aspx

I see how this is actually very broadly scoped, but it seems hideously over-engineered and I can see why so many people seem to have Oslo wrong. It does for business processes what the database does for business information. With a DB, people are able to view and change business information, and design business information systems, but with Oslo (and Dublin) people are able to view and change and design business processes. I think...

The M language and M grammar are meant for people to be able to design their own data repositories and programming languages, or rather for people to define their own DSLs to describe and persist their business-specific processes and information.

How is this better than just hiring a developer though? It seems like the entire idea of giving people DSL authoring tools is to allow businesses to develop their own specialized languages to permit communication between people who don't normally use programming languages.

But isn't this just candygrammar by a different name? The problem with communicating in context free grammars isn't that people don't know the rules of the grammar, this is the comparably easy part, it's that they don't know how to express their idea in a logically consistent fashion. If I'm understanding Oslo correctly, I think it's a crazy idea (imagine me saying it with a Richard Feynman voice "It's CRAZY!"), just because it doesn't address the real problem in business processes, namely, people don't know how to design a process in any language :P


6. Joe left...
Thu 07 May 09 8:56 pm :: http://blogs.windowsclient.net/joeyw

One thing that I really don't get with Oslo is the fact that the repository is a SQL Server DB. Surely this is restricting my models to the limits of SQL Server. There are some XSD constructs that I cannot do very easily in SQL Server. What about modeling services and SOAP porttypes? Also, I was expecting Quadrant to be a model editing tool, rather than a generic graphical DSL.


Tag Related Posts

Tour of Oslo: Storing Models in the Repository

Tue 28 Apr 09 12:36 P GMT-05
tags:      

Tour of Oslo: Using Models to Generate SQL

Mon 27 Apr 09 5:50 P GMT-05
tags:          

Microsoft Codename "Oslo" Distilled

Mon 27 Apr 09 12:46 P GMT-05