Entity Framework stored procedure not available

I added a link to the stored procedure in my edmx file, then right-click on it and select "Create Function Import", it was added to the "Import Objects" folder in the EntityContainer in the model browser.

As I understand it, I should use it like this:

sampleEntities db = new sampleEntities();
db.SampleStoredProcedure();

but it does not appear on the db object. Is there any step that I am missing? The import of the function is set to public, has no return value, and one parameter that I can see when I expand it.

+3
source share
2 answers

( ) ? , :

, Visual Basic # .

, Entity Framework:

"" "" . , " " , , ObjectContext .

+7

EntityCommand, , , :

public bool ExecuteCMD(string Command) 
{
    using (var entities = new DbEntities())
    {
        var conn = new System.Data.EntityClient.EntityConnection(entities.Connection.ConnectionString);
        try
        {
            conn.Open();
            using (EntityCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = "DbEntities." + Command;
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }
}
+3

Source: https://habr.com/ru/post/1732439/


All Articles