Consider I have built DAL.dll which is a class library containing an Entity Framework edmx. In the Designer.cs, the following imported stored procedure is defined:
<Function Name="Login_User" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="Login_Name" Type="nvarchar" Mode="In" />
<Parameter Name="Password" Type="nvarchar" Mode="In" />
<Parameter Name="SP_Return_Code" Type="int" Mode="InOut" />
</Function>
Below I have used Reflection to find type1 as an ObjectContext type. How do I discover the Login_User stored procedure by reflecting type1?
private static void ReflectionTest()
{
var asm = Assembly.LoadFrom(@"C:\DAL.dll");
// list stored procedure calls
foreach (var type in asm.GetTypes())
{
if (type.BaseType == typeof(ObjectContext))
{
foreach (var type1 in type.GetMethods())
{
// how do I reflect against type1 for its stored procedure names?
}
}
}
}
First you will need to import your stored procedures as
Functionin your Entity model. Refer to this link for HowTo: http://ashishrocks.wordpress.com/2010/09/05/entity-framework-using-select-stored-procedures-for-entities-having-same-column-names/At the time you are doing this, make sure you use some kind of naming convention for your
Function Import Name. For example, prefixSP_to all your stored procedure function imports.Once you add your SPs as functions in your Entity Model, you should be able to see them in your
Model.Designer.cs. Compile updated DAL.Now you can get your stored procedures like this: