Export (0) Print
Expand All

Simple Types (Metadata)

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

In the Entity Data Model (EDM), simple types consist of primitive types. For more information about the simple types in the EDM, see Simple Types (EDM).

ADO.NET provides a PrimitiveType, which is derived from the SimpleType, to describe the .NET Framework primitive types, EDM primitive types, and storage provider-specific primitive types. The ADO.NET metadata infrastructure handles the mappings between the primitive types in the object, conceptual, and storage models. The object and conceptual model primitive types always have one-to-one default matches. Storage model primitive types depend on the storage provider or database used.

Each storage provider defines its own primitive types. The ADO.NET metadata infrastructure requests the definitions of the primitive types from the storage provider during runtime. Each storage provider must declare its primitive types in an XML document called the provider manifest.

The provider manifest file includes the list of the provider primitive types, the mappings between the conceptual and storage model primitive types, and the promotion and conversion rules between the conceptual and storage model primitive types.

The following code sample demonstrates how to get a metadata workspace from the connection and then use that metadata workspace to retrieve information about a specific primitive type and all other primitive types in the specified model. Note that the metadata workspace is a runtime service component that provides support for retrieving metadata.

The code sample uses a CSpace and a SSpace to specify the models. The CSpace represents the default name for the conceptual model. The SSpace represents the default name for the storage model. The code sample uses the connection string that is provided in the application config file. For an example of the application config file, see Using the AdventureWorks Object Model (EDM).

using System;
using System.Data;
using System.Data.EntityClient;
using System.Collections.ObjectModel;
using System.Data.Metadata.Edm;

class GetPrimitiveTypesExample
{
  static void Main()
  {
    try
    {
      // Establish a connection to the underlying data provider by 
      // using the connection string specified in the config file.
      using (EntityConnection connection = 
               new EntityConnection("Name=AdventureWorksEntities"))
      {
         // Open the connection.
         connection.Open();

         // Access the metadata workspace.
         MetadataWorkspace workspace = 
            connection.GetMetadataWorkspace();

         // Get primitive types from the conceptual model.
         GetPrimitiveTypes(workspace, DataSpace.CSpace);

         // Get primitive types from the storage model.
         GetPrimitiveTypes(workspace, DataSpace.SSpace);
      }
    }
    catch (MetadataException exceptionMetadata)
    {
        Console.WriteLine("MetadataException: {0}", 
                         exceptionMetadata.Message);
    }
    catch (System.Data.MappingException exceptionMapping)
    {
        Console.WriteLine("MappingException: {0}",
                         exceptionMapping.Message);
    }
  }

  private static void GetPrimitiveTypes(
       MetadataWorkspace workspace, DataSpace model)
  {
    // Get a collection of the primitive types.
    ReadOnlyCollection<PrimitiveType> primitiveTypes =
            workspace.GetPrimitiveTypes(model);

    // Iterate through the collection to get each primitive type.
    foreach (PrimitiveType prim in primitiveTypes)
    {
       Console.WriteLine(
          "Type BuiltInTypeKind: {0}, Type: {1}, Type in Model: {2} ",
          prim.BuiltInTypeKind, prim.ClrEquivalentType.FullName, 
          prim.FullName);

     }
  }
}

See Also

Community Additions

Show:
© 2014 Microsoft