开发者

How to extract only Stored Procedures from the MetadataWorkspace?

开发者 https://www.devze.com 2023-02-13 05:37 出处:网络
Guys, is there a way to extract only the stored procedures from the storage model (SSDL) of 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 Metad开发者_如何学CataWorkspace (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.


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;
}


I've recently needed to find this out too. The IsComposable attribute should be used to determine if the EdmFunction is a stored procedure or user defined function.

EdmFunction.IsComposableAttribute Property

Gets or sets whether this instance is mapped to a function or to a stored procedure.

Property Value

Type: System.Boolean

true if this instance is mapped to a function; false if this instance is mapped to a stored procedure.

Version Information

.NET Framework

Available since 4.5

https://msdn.microsoft.com/en-us/library/system.data.metadata.edm.edmfunction.iscomposableattribute(v=vs.110).aspx

(I know this is an old question ,but this is the top result on Google when I was searching for the answer. Maybe this will help someone else.)

0

精彩评论

暂无评论...
验证码 换一张
取 消