Search code examples
entity-frameworkentity-framework-4

How to extract only Stored Procedures from the MetadataWorkspace?


Guys, is there a way to extract only the stored procedures from the storage model (SSDL) of the MetadataWorkspace?

Currently, I am using the following code for extracting stored procedures from the MetadataWorkspace (I am checking the BuiltInAttribute of the EdmFunction object):

public static List<EdmFunction> TryGetSsdlFunctions( this MetadataWorkspace metadataWorkspace )
{
    List<EdmFunction> functions = new List<EdmFunction>();

    foreach ( EdmFunction function in metadataWorkspace.GetItems<EdmFunction>( DataSpace.SSpace ) )
    {
        MetadataProperty builtInAttribute = function.MetadataProperties.FirstOrDefault( p => p.Name == "BuiltInAttribute" );
        if ( builtInAttribute != null && Convert.ToBoolean( builtInAttribute.Value.ToString() ) == false )
        {
            functions.Add( function );
        }
    }

    return functions;
}

The problem here is that besides the stored procedures, this will return all functions included in the data model too. And I want only stored procedures. I see there are differences in the value of the IsComposable attribute but I am not sure if this is a reliable criterion.

Thanks in advance.

p.s: If you think there is a smarter way for extracting stored procedures from the workspace, please share.


Solution

  • What about this variant?

    public static List<EdmFunction> TryGetSsdlFunctions( this MetadataWorkspace metadataWorkspace ) { 
      List<EdmFunction> functions = (from func in metadataWorkspace.GetItems<EdmFunction>(DataSpace.SSpace) )
                                    where func.ReturnParameter == null
                                    select func).ToList();
      return functions;
    }