🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Moving your work from MDriven Designer to MDriven Framework
This page was created by Alexandra on 2018-10-21. Last edited by Wikiadmin on 2026-07-29.

You can move a model created in MDriven Designer into a Visual Studio MDriven Framework solution when you need strongly typed C# access to the model and want to build a custom .NET client, such as a WPF application.

MDriven Framework embeds the MDriven modeling workflow in Visual Studio and generates the business-layer code that corresponds to your model. You can then add handwritten C# in separate files while continuing to evolve the model.

When to use this workflow

Use this workflow when you have already modeled classes, associations, ViewModels, and OCL logic in MDriven Designer and now need a Visual Studio solution that can access model types from C#.

For example, if your Designer model contains Customer and Order, the generated Framework project gives your C# code typed access to those model classes. You can use that code in a WPF window, a service, or CodeDress used by MDriven Turnkey.

This page describes the WPF setup shown by the ECO7 Visual Studio templates. For creating or migrating current .NET projects, follow Documentation:Migrating From MDriven .NET Framework to .NET Core and the guidance in Documentation:Framework.

Before you start

Make sure that:

  • You have saved the model you want to move from MDriven Designer.
  • MDriven Framework is installed in Visual Studio.
  • Visual Studio shows the ECO7 project templates when you create a new project.
  • You know which packages in the template model are only examples and should not remain in your application.

The Framework model format is .ecomdl. It is multi-file and uncompressed, which makes changes easier to inspect and merge in source-control systems such as Git and SVN. You can open the .ecomdl model structure in MDriven Designer, so the same model can continue to be edited in Designer and Visual Studio.

Create the Visual Studio solution

  1. Start Visual Studio.
  2. Create a new project using the EcoProject1 template. This project provides the model and generated-code setup.
  3. Add a second project using the standard WPF Application template.
  4. In the EcoProject1 project, open the EcoMdl model file.

Import the Designer model

  1. In the Modlr Toolbox window, right-click the Packages note.
  2. Choose Import.
  3. Select the model created in MDriven Designer and import it.
  4. Review the packages in the resulting model. Delete packages that were included only by the EcoProject1 template and are not part of your application.
  5. On the Modlr surface, select Update Code. This generates or updates the C# code that represents the model.
  6. Build the full solution.
  7. Add the imported package to the EcoSpace.

An EcoSpace is the generated runtime context for the model. In the example below, EcoProject1EcoSpace is the EcoSpace generated by the EcoProject1 project. Your generated class name can differ if your project has a different name.

Reference the Framework project from WPF

The WPF project must reference the project that contains the EcoSpace and generated model code. Add a project reference from the WPF application to EcoSpaceAndModel.

The WPF project also needs the assemblies used by the WECPOF tab-based UI shown in this walkthrough:

Reference Purpose in this walkthrough
Eco.Handles Required ECO handle support.
Eco.Interfaces Required ECO interfaces.
Eco.LinqExtender LINQ extension support for ECO.
Eco.WPF WPF support for ECO.
WECPOFLogic Provides the WECPOFTabBased control used below.

Display the model with WECPOFTabBased

WECPOF is the model-driven WPF UI approach used here to give the WPF application an initial UI comparable to the Designer prototyper. Add the control to the main window XAML.

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wecpof="clr-namespace:WECPOFLogic;assembly=WECPOFLogic"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <wecpof:WECPOFTabBased x:Name="wECPOFTabBased" />
    </Grid>
</Window>

Initialize and close the EcoSpace

In the window code-behind, create and activate the EcoSpace, enable asynchronous handling, and pass the EcoSpace to the WECPOF control. The closing handler prevents the window from closing while the EcoSpace has unsaved objects. The closed handler deactivates the EcoSpace.

public partial class MainWindow : Window
{
    EcoProject1EcoSpace _es;

    public MainWindow()
    {
        InitializeComponent();

        // Instantiate the EcoSpace generated for your project.
        _es = new EcoProject1EcoSpace();
        _es.Active = true;

        // Keep the UI responsive while data is loaded or saved.
        EcoServiceHelper.GetAsyncSupportService(_es).TurnOnAsyncHandling();

        // Give the model-driven WPF control access to the EcoSpace.
        wECPOFTabBased.EasyInit(_es);

        this.Closing += MainWindow_Closing;
        this.Closed += MainWindow_Closed;
    }

    void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // Do not close while there are unsaved changes.
        e.Cancel = _es.DirtyList.AllDirtyObjects().Count > 0;
    }

    void MainWindow_Closed(object sender, EventArgs e)
    {
        // Deactivate the EcoSpace when the application exits.
        _es.Active = false;
    }
}

Replace EcoProject1EcoSpace with the EcoSpace class generated for your project if it has a different name.

Build and run

  1. Select BuildBuild Solution. Resolve any missing project or assembly references before continuing.
  2. Press F5 to build and start the WPF application.
  3. Verify that the WECPOF tab-based UI initializes against the imported model.
  4. Make a model change, select Update Code on the Modlr surface, rebuild the solution, and verify the application again.

Continue development in C#

At this point, the imported model remains the central definition of your application. Continue to place declarative queries and rules in OCL where appropriate, and implement application-specific behavior in C# against the generated model types.

You can continue with the WECPOF-based WPF UI, customize the WPF presentation with styles and content overrides, or use standard MVVM patterns and generate code from ViewModels. MDriven Framework also supports using compiled model logic with CodeDress in MDriven Turnkey; see Documentation:MDriven Framework for the relationship between Framework and Turnkey.

Important maintenance practice

Treat the .ecomdl files as source code:

  • Store the full model structure in version control.
  • Review model changes together with generated-code changes.
  • Regenerate code with Update Code after changing the model.
  • Do not make application-specific edits in generated files when a separate handwritten partial class can hold the same logic.

See also