Tuesday, August 24, 2010

Reverse engineer a database

Reverse engineering is what we call the process that takes a given database and turns it into a model driven “thing”.



You just need to give a valid connection string to it; in this case a use the MusicStoreDb from a MicrosoftSample:


You start by Analyzing the database:


And then you “Go!” – be aware of that this process will empty the package you started from and fill it with the stuff from the reverse engineer process:



Giving us this in the modlr tree:


And I will drag these classes out on a diagram to get this:


And that is enough information to run the model against the exact same database as we reversed it from:


Giving us a way to use the trusty AutoForms and EcoSpaceDebugger to look at the data and change it if we want:


In this particular database the RecordId, ArtistId and sofort are of type int in the database and are designed with “Is Identity==true” in SqlExpress. Also the “Identity Increment” is set in SqlExpress.

The Reverse algorithm gave us a model with int Attributes for the ID – we want ECO to be able to use that Key scheme instead of the standard ECO_ID – how is that done? Like this:


The PrimaryKey setting we got from the reversing process and the PrimaryKeyMapper I set to ”AutoInc” - an Eco-supplied primary key mapper with that name that handles the normal AutoIncrease behavior of databases. (You can create your own named mappers in ECO for visualStudio).

And for the Attribute we must also say that it is DbAssigned; that forces ECO to omit setting the primary key on first save, and also forces ECO to read the saved row back from the database to get the actual assigned key (which we need to use as a foreign key in related objects) :


This is actually enough to be able to create new objects from the ecospace debugger and have them inserted in the database (or from code or wecpof or what have you). If you follow along in this brief and try to save a new Album you will notice 2 SQLServer exceptions – Both Genre and Artist foreign keys are marked NOT NULL in the DB – handle this by assigning an Artist and a Genre to the new Album with AutoForms drag and drop.

Database evolve

So when you have reached this far you may have the need for changing the model – just like any developer you might get an uncontrollable urge to make the model look more like reality from time to time.

To use the Model Evolve mechanism – that calculates what needs to be changed in the database by comparing a new and old db script – we have to allow ECO to write the (current)script to the database. If we do not do this ECO will not have any “old” script to compare the new script with that ECO derives from your current model.

In ECO for VisualStudio you can choose to store the script some other way by using the ORMappingProvider components in your EcoSpace – but in Gaffr/AppComplete you do not have any code so you really must allow us to store it in the database. Note that this is only if you want to use the Database Evolve mechanism.

To write the Script to the Database open up the prototyper once more by hitting “Run” :


And once we have done this one time operation, that is only necessary for reversed databases (since standard eco databases has these from the start), we can do some model changes:


And “Run” and “Evolve”:


Looking in the SQL Script tab in the dialog above we can see the expected script that ECO will send to the database:

/* Add column [Album].ReleaseDate */

That wraps up this presentation of the Reverse (engineer) database function in ECO and Gaffr/AppComplete.

Saturday, August 14, 2010

Silverlight 4 – Out of browser – Model driven

One reason for going for an Out of browser Silverlight application is that you get elevated permissions. You can open files from My images and the like…

So getting an image into your WECPOF/AppComplete UI like this:

WECPOF AppComplete

… only requires you to add the attribute to your ViewModel:

ViewModel Editor

… and that you also have the attribute in your model:

Model UML

The one thing you need to keep in mind is that the ViewModelUserControl will not know what to do with your Blob value unless you give it a hint with a Tagged Value:


The TaggedValue need to be set in order for the logic to assume that the data in the blob is an Image. Currently this works the same way for ViewModelUserControls for Silverlight, WPF, Windows forms and I think also ASP.NET.

WECPOF/AppComplete is a prototyping and/or runtime environment for Model driven system development using Enterprise Core Objects for VisualStudio 2010. Work faster, with better quality.

Friday, August 6, 2010

Silverlight ViewModel UserControl

ViewModel UserControl is what we call the UserControl that given an ecospace type and a ViewModel name already in design time can derive a UI based on the UI-hints that the ViewModel definition might have, and in runtime, given an EcoSpace and a Root object, turns into a fully bound UI; derived purely from a declarative idea about what you want to achieve.

The ViewModel UserControls have different implementations for different UI-architectures of course. I have described the ViewModel UserControl for ASP.NET here; http://theblog.capableobjects.com/2010/02/viewmodels-in-aspnet.html .

The ViewModel UserControl for WindowsForms UserControl I have not really written anything about – but we use them frequently in Modlr – like in the Actions-dialog.

The ViewModel UserControl for WPF I have written about on numerous occasions, for example here; http://theblog.capableobjects.com/2010/01/viewmodel.html and not to mention that the WPF ViewModel UserControl is core to WECPOF / AppComplete that is discussed here http://theblog.capableobjects.com/2010/05/wecpof-icing-on-model-driven-cake.html

And earlier this week I wrote about the ViewModels now being consumable in Silverlight via generated code ; http://theblog.capableobjects.com/2010/07/silverlight-and-viewmodels-and-eco-and.html in the available beta builds of ECO6 for Visual Studio 2010.

Today we present the ViewModel UserControl for Silverlight – named ViewModelSLUserControl. That we were about to present such a control must have been obvious to everyone but today it is actually here.

The demo project is in the Demos folder named SLDemo20100806_UserControl

In the solution explorer this looks neat an tidy:


Click open the EcoModel1:


Clicking on the ViewModels button brings up the ViewModel editor:


I wanted to show a somewhat complex sample and at the same time really test the Silverlight implementation of the ViewModel UserControl. So I added comboboxes, and master detail grids in two steps followed by a detailing of the selected row of the last grid in discrete components.

I also added columns to the ViewModel for each of the auto created/ auto maintained vCurrent_ variables that comes with the ViewModel.

Even if this sort of UI is considered advanced by many standards (never mind the look of it just now) it is easy to produce and maintain in the ViewModel editor. And this is the whole point of the ViewModel UserControls – fast as your thoughts. The interesting part is really what you do with the time you do not spend in the ViewModel editor – the time you have gained by not being forced to create standard UI’s manually, and not needing to maintain them manually.

Consuming this in Silverlight is easy (from today and forward)

   1: public Page()
   2: {
   3:     InitializeComponent();
   5:     DequeuerSL.Active = true;
   6:     _ecoSpace = new EcoSilverlightDemoEcoSpace();
   7:     _ecoSpace.Active = true;
   8:     ViewModelDefinitionsInApplication.Init(_ecoSpace);
  11:     CreateDemoData();
  13:     ccc = new ViewModelSLUserControl();
  14:     ccc.EcoSpaceType = typeof(EcoSilverlightDemoEcoSpace);
  15:     ccc.SetEcoSpace(_ecoSpace);
  16:     ccc.ViewModelName = "TestViewModel";
  17:     TOPPanel.Children.Insert(0,ccc);

And you get this in runtime:


And I could not resist to spend some time to find out how far of WECPOF for Silverlight was now that the ViewModelSLUserControl was in place. It turned out that the biggest challenge was the Menus. Main menu is not in Silverlight (or the toolkit), and the ContextMenu’s that are in the Toolkit does not support hierarchical menu items – crap. I found a good start of implementing the Menus at CodePlex - http://sl3menu.codeplex.com/ , I will use this until the Toolkit catches on…

WECPOF / AppComplete for Silverlight actually works!


I added the sample to a server with IIS7 : http://lulea.dyndns.org/EcoSilverlightDemo.Web/EcoSilverlightDemoTestPage.aspx 

As always – typos –> email me and I will fix & comments appreciated

The build that contains the sample and the necessary ECO6 versions is posted at the end of this topic: http://www.capableobjects.com/apps/InstantForum414/FindPost5469.aspx , if there are newer builds when you read this – use them instead…

Contact Us | Terms of Use | Privacy Statement © 2009 CapableObjects