Compartir a través de


How to: Create and Use Folders for New Model Instances

[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 of six tasks that apply SQL Server Modeling Services patterns to a Microsoft code name “M” model. In this task, you use Microsoft code name “M” to define instances of the SetupApplication model. This is very similar to the steps in another task, How to: Add Model Instances using "M". However, that previous task added instances to a version of the SetupApplication model that did not follow Modeling Services patterns. In this topic, the SetupApplication model uses Modeling Services patterns.

The Folder pattern is one of the Modeling Services patterns that the new SetupApplication model uses. Folders in SQL Server Modeling Services help to provide organization for data and additional security when combined with updateable views. For more information, see  Using Folders and Ids. This topic will demonstrate how to use “M” to create a new Folder for use with new SetupApplication records.

To add the MyNotepad.m file back into the SetupApplication project

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

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

  3. In the Add Existing Item dialog, change the drop-down filter list to select All Files.

  4. In the SetupApplication project directory, select the MyNotepad.m file that you previously excluded from the project.

    Note

    The MyNotepad project was created in a previous task of this tutorial. For more information about how to create this project, see How to: Add Model Instances using "M".

  5. Click Add to add this file to the project.

To modify the MyNotepad.m file to create a new Modeling Services Folder

  1. In Visual Studio 2010, open the MyNotepad.m file.

  2. To create a new Modeling Services Folder, first import the Repository.Item module.

        import Repository.Item;
    
  3. Below this import statement, create an instance of the Repository.Item::FoldersTable extent. Provide a label of MyNotepadFolder. Set the Name field to "MyNotepadFolder" and the Folder field to FoldersTable.Repository.

        Repository.Item::FoldersTable
        {
            MyNotepadFolder
            {
                Name => "MyNotepadFolder",
                Folder => FoldersTable.Repository
            }
        }
    

    Note

    The FoldersTable.Repository label refers to the root level Repository Folder that is installed by the Base Domain Library. By setting the Folder field to this value, the new MyNotepadFolder Folder becomes a child of the Repository Folder. The full text path to this new Folder is Repository/MyNotepadFolder.

To modify the MyNotepad.m file to use the MyNotepadFolder Folder

  1. Because of the extent name changes in the SetupApplication model, the extent names in the MyNodepad.m file must be changed. Append the word "Table" to the end of the current extent names. For example, the Products extent becomes ProductsTable. Do this for each extent definition and for any field references to extents.

  2. Assign a value for the Folder field in each extent. Refer to the label of the new Folder, FoldersTable.MyNotepadFolder. The following example shows this new field and assignment with the SetupApplication::ProductsTable extent.

        ProductsTable 
        {
            MyNotepad
            {
                Folder => FoldersTable.MyNotepadFolder,
                ProductId => #[D65D2125-560B-4BA9-BDCA-3B3BCD3F7B70], 
                UpgradeCode => #[AC5C9DAC-B3F0-469A-8F1A-02C2566EEE33], 
                Version => "1.0.0.0",
                Name => "MyNotepad",
                Manufacturer => "MyNotepad Corp."
            }
        }
    
  3. On the Build menu, click Rebuild Solution.

    Note

    You can ignore any warnings about EDM generation.

  4. In the Output window, verify that the build succeeded.

To deploy the SetupApplication model instance to a Modeling Services database

  1. Before re-deploying this model in Visual Studio 2010, you must first recreate the target SetupApplicationDB database. For more information, see How to: Deploy a Domain that Uses SQL Server Modeling Services Patterns.

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

  3. In the Output window, verify that the deployment succeeded.

  4. Optionally, observe the rows in the views of the SetupApplication schema. For example, there should be four rows in the [SetupApplication].[Directories] view. For more information about viewing the model instance using SQL Server Management Studio, see How to: View a Deployed "M" Model in the Database. For more information about viewing the model instances using Microsoft code name “Quadrant”, see How to: View and Edit Models Using "Quadrant".

    Note

    T his step is optional and is intended only to validate that the data was successfully loaded into the SQL Server Modeling Services.

Example

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

module SetupApplication
{  
    import Repository.Item;

    Repository.Item::FoldersTable
    {
        MyNotepadFolder
        {
            Name => "MyNotepadFolder",
            Folder => FoldersTable.Repository
        }
    }

    ProductsTable 
    {
        MyNotepad
        {
            Folder => FoldersTable.MyNotepadFolder,
            ProductId => #[D65D2125-560B-4BA9-BDCA-3B3BCD3F7B70], 
            UpgradeCode => #[AC5C9DAC-B3F0-469A-8F1A-02C2566EEE33], 
            Version => "1.0.0.0",
            Name => "MyNotepad",
            Manufacturer => "MyNotepad Corp."
        }
    }
    
 
    PackagesTable 
    {
        Package1 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            Description => "A copy of Notepad",
            Manufacturer => ProductsTable.MyNotepad.Manufacturer,
            Keywords => { "Installer", "My", "Notepad", "Sample" }
        }
    }
    
    
    MediaTable 
    {
        MediaTable1 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            Cabinet => "setup.cab",
            EmbedCab => true
        }
    }
    
    
    DirectoriesTable 
    {
        TARGETDIR 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            SpecialType => "TARGETDIR"
        },
        ProgramFilesTableFolder 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            ParentDirectory => DirectoriesTable.TARGETDIR,
            SpecialType => "ProgramFilesTableFolder"
        },
        CompanyDir 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            ParentDirectory => DirectoriesTable.ProgramFilesTableFolder,
            Name => "MyNotepad Corp."
        },
        INSTALLDIR 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            ParentDirectory => DirectoriesTable.CompanyDir,
            SpecialType => "INSTALLDIR",
            Name => "My NotePad"
        }
    }    
    
    
    ComponentsTable 
    {
        Core 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Directory => DirectoriesTable.INSTALLDIR
        } 
    }

        
    FeaturesTable 
    {
        Core 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Product => ProductsTable.MyNotepad,
            ComponentRefs => { ComponentsTable.Core }
        }    
    }

    
    FilesTable 
    {
        MyNotepadExe 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Component => ComponentsTable.Core,
            Name => "MyNotepad.exe",
            Source => "C:\\SetupApplication\\MyNotepad\\MyNotepad.exe"
        },   
        DependencyDll 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Component => ComponentsTable.Core,
            Name => "Dependency.txt",
            Source => "C:\\SetupApplication\\MyNotepad\\dependency.txt"
        },   
        ManualTxt 
        {
            Folder => FoldersTable.MyNotepadFolder,
            Component => ComponentsTable.Core,
            Name => "Manual.txt",
            Source => "C:\\SetupApplication\\MyNotepad\\manual.txt"
        }
    }
}

See Also

Concepts

Adding Modeling Services Patterns to the SetupApplication Model

Other Resources

Getting Started with the SQL Server Modeling CTP (SetupApplication Tutorial)