How to invoke/run Stored Procedures on the Entity Framework
October 23rd, 2009
This one was a hard one to guess. But it's something like:
C#:
-
DbConnection conn = Entities.Connection;
-
DbCommand cmd = conn.CreateCommand();
-
-
string spname= "DoSomething";
-
string entities = "Entities";
-
-
cmd.CommandType = CommandType.StoredProcedure;
-
cmd.CommandText = string.Format("{0}.{1}", entities, spname);
You need to go to the edmx file, right click, add -> function. The tricky part on this was guessing the Entities.DoSomething name for the stored procedure. Nuno did the guessing part.
Related Posts
- How to export to SQL from MS SQL Server
- [SQL Server] Creating a database and a user for it in C#
- How Multi-platform translates to more reliability
- Funny problem with Vista's firewall




October 23rd, 2009 at 2:41 pm
Another (easier) way is to create a dbml file and register there the stored procedures. You’ll then be able to use them on a data context class.