Share via


How to: Add Model Instances using "M"

[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 fourth of five tasks that create a data-driven application by using the SQL Server Modeling CTP technologies. In this task, you use Microsoft code name “M” to define instances of the SetupApplication model. You then load these instances into the previously created SetupApplicationDB database. For an overview of this tutorial, see Getting Started with the SQL Server Modeling CTP (SetupApplication Tutorial).

Note

This task focuses on using “M” to write and load the instance data. There are other programmatic options for loading data into a target database. For more information about these alternatives, see Loading Domain Models with Data.

To prepare test files for the setup application instance

  1. Create a subdirectory named MyNotepad in the tutorial directory C:\SetupApplication.

  2. Copy Notepad.exe from the Windows\System32 directory to the new C:\SetupApplication\MyNotepad directory.

  3. Rename the copied Notepad.exe to MyNotepad.exe.

  4. In the same directory, create a blank text file named Dependency.txt to represent an application dependency.

  5. Create another blank text file named Manual.txt to represent the application help file.

To use "M" to add SetupApplication model instances

  1. In Visual Studio 2010, open the previously created SetupApplication project.

  2. In Solution Explorer, right-click the SetupApplication project, select Add, and then click New Item.

  3. In the Add New Item dialog, select the "M" Model Data template. Name the new file MyNotepad.m, and then click Add.

  4. In the Entity Data Model Wizard, select Default Model, and then click Finish.

  5. In the code editor, delete the contents of the MyNotepad.m file.

  6. First, scope the data instances with the module name of the SetupApplication model.

    module SetupApplication
    {
    
    }
    
  7. Inside the module braces, define the properties of a setup application named My Notepad. Add data to the Products, Packages, Media, Directories, Components, and Features extents. This defines an instance of the SetupApplication model that an application can read to create and install a Windows Installer file.

        Products 
        {
            MyNotepad
            {
                ProductId => #[D65D2125-560B-4BA9-BDCA-3B3BCD3F7B70], 
                UpgradeCode => #[AC5C9DAC-B3F0-469A-8F1A-02C2566EEE33], 
                Version => "1.0.0.0",
                Name => "MyNotepad",
                Manufacturer => "MyNotepad Corp."
            }
        }
    
    
        Packages 
        {
            Package1 
            {
                Product => Products.MyNotepad,
                Description => "A copy of Notepad",
                Manufacturer => Products.MyNotepad.Manufacturer,
                Keywords => { "Installer", "My", "Notepad", "Sample" }
            }
        }
    
    
        Media 
        {
            Media1 
            {
                Product => Products.MyNotepad,
                Cabinet => "setup.cab",
                EmbedCab => true
            }
        }
    
    
        Directories 
        {
            TARGETDIR 
            {
                Product => Products.MyNotepad,
                SpecialType => "TARGETDIR"
            },
            ProgramFilesFolder 
            {
                Product => Products.MyNotepad,
                ParentDirectory => Directories.TARGETDIR,
                SpecialType => "ProgramFilesFolder"
            },
            CompanyDir 
            {
                Product => Products.MyNotepad,
                ParentDirectory => Directories.ProgramFilesFolder,
                Name => "MyNotepad Corp."
            },
            INSTALLDIR 
            {
                Product => Products.MyNotepad,
                ParentDirectory => Directories.CompanyDir,
                SpecialType => "INSTALLDIR",
                Name => "My NotePad"
            }
        }    
    
    
        Components 
        {
            Core 
            {
                Directory => Directories.INSTALLDIR
            } 
        }
    
    
        Features 
        {
            Core 
            {
                Product => Products.MyNotepad,
                ComponentRefs => { Components.Core }
            }    
        }
    

    Tip

    Compare the instance data in this example to the original model, SetupApplication.m. For more information, see  How to: Create a Model Using Visual Studio and "M". In this example, extents use labels to reference other extent instances by name. For example, the Products instance is named Products.MyNotepad. Several other extents use this label when a reference to a Product instance is required by the model definition.

  8. Also add an instance for the Files extent. Verify that the file paths in this instance match the files you created earlier in this task.

        Files 
        {
            MyNotepadExe 
            {
                Component => Components.Core,
                Name => "MyNotepad.exe",
                Source => "C:\\SetupApplication\\MyNotepad\\MyNotepad.exe"
            },   
            DependencyDll 
            {
                Component => Components.Core,
                Name => "Dependency.txt",
                Source => "C:\\SetupApplication\\MyNotepad\\dependency.txt"
            },   
            ManualTxt 
            {
                Component => Components.Core,
                Name => "Manual.txt",
                Source => "C:\\SetupApplication\\MyNotepad\\manual.txt"
            }
        }
    

To deploy the model instance to the database

  1. On the File menu, click Save All.

  2. In Solution Explorer, right-click the SetupApplication project, and then click Deploy.

  3. On the View menu, click Output.

  4. The output window should indicate a successful build and deploy.

The previous steps in this tutorial created the SetupApplication model schema and inserted instance data for a MyNotepad setup application. The next step builds the application that reads and acts on this model data. For more information, see How to: Create a Custom Application to "Run" a SetupApplication Model Instance.

Example

The following code is the complete “M” source code for the MyNotepad.m file.

module SetupApplication
{
    Products 
    {
        MyNotepad
        {
            ProductId => #[D65D2125-560B-4BA9-BDCA-3B3BCD3F7B70], 
            UpgradeCode => #[AC5C9DAC-B3F0-469A-8F1A-02C2566EEE33], 
            Version => "1.0.0.0",
            Name => "MyNotepad",
            Manufacturer => "MyNotepad Corp."
        }
    }
    
 
    Packages 
    {
        Package1 
        {
            Product => Products.MyNotepad,
            Description => "A copy of Notepad",
            Manufacturer => Products.MyNotepad.Manufacturer,
            Keywords => { "Installer", "My", "Notepad", "Sample" }
        }
    }
    
    
    Media 
    {
        Media1 
        {
            Product => Products.MyNotepad,
            Cabinet => "setup.cab",
            EmbedCab => true
        }
    }
    
    
    Directories 
    {
        TARGETDIR 
        {
            Product => Products.MyNotepad,
            SpecialType => "TARGETDIR"
        },
        ProgramFilesFolder 
        {
            Product => Products.MyNotepad,
            ParentDirectory => Directories.TARGETDIR,
            SpecialType => "ProgramFilesFolder"
        },
        CompanyDir 
        {
            Product => Products.MyNotepad,
            ParentDirectory => Directories.ProgramFilesFolder,
            Name => "MyNotepad Corp."
        },
        INSTALLDIR 
        {
            Product => Products.MyNotepad,
            ParentDirectory => Directories.CompanyDir,
            SpecialType => "INSTALLDIR",
            Name => "My NotePad"
        }
    }    
    
    
    Components 
    {
        Core 
        {
            Directory => Directories.INSTALLDIR
        } 
    }

        
    Features 
    {
        Core 
        {
            Product => Products.MyNotepad,
            ComponentRefs => { Components.Core }
        }    
    }

    
    Files 
    {
        MyNotepadExe 
        {
            Component => Components.Core,
            Name => "MyNotepad.exe",
            Source => "C:\\SetupApplication\\MyNotepad\\MyNotepad.exe"
        },   
        DependencyDll 
        {
            Component => Components.Core,
            Name => "Dependency.txt",
            Source => "C:\\SetupApplication\\MyNotepad\\dependency.txt"
        },   
        ManualTxt 
        {
            Component => Components.Core,
            Name => "Manual.txt",
            Source => "C:\\SetupApplication\\MyNotepad\\manual.txt"
        }
    }
}

See Also

Concepts

Creating and Using the SetupApplication Model