Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
HI All,

I am working on Entity freamework . I m having VisualStudio 2008, Sql 2008pro

These things i am having . How do i call store procedure . In 2010 its possible. But 2008 Is it Possible??

Thanks,
SarathKumar.N
Posted

1 solution

well i don't know if 2008 is different from 2010..

but that code works on 2010,i think that could work also on 2008..

try it...
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Objects;
using System.Data.SqlClient;
using System.Data.EntityClient;



C#
public static DataTable ExecuteStoredProcedure(ObjectContext db, string storedProcedureName, List<SqlParameter> parameters)
     {
         var connectionString = ((EntityConnection)db.Connection).StoreConnection.ConnectionString;
         using (var data = new DataTable())
         {
             using (var conn = new SqlConnection(connectionString))
             {
                 using (var cmd = conn.CreateCommand())
                 {
                     cmd.CommandText = storedProcedureName;
                     cmd.CommandType = CommandType.StoredProcedure;
                     cmd.Parameters.AddRange(parameters.ToArray());

                     using (var adapter = new SqlDataAdapter(cmd))
                     {
                         adapter.Fill(data);
                     }
                 }
             }

             return data;
         }
     }


i remember that i created a View with the same schema that i excepected from the stored
and i imported it as entity in the model.
so the "entity" has the same imprint as the view
 
Share this answer
 
v2
Comments
Sarathkumar Nallathamby 21-Jan-13 23:35pm    
Thanks Alot buddy!! Do u know what are the disadvantages of Entity ??? Because I am planning to implement on my live project .. so Need consider the performance too.. Is there any performance problem in that..?
nrgjack 22-Jan-13 2:47am    
performance, well using linqToEntity you have a very little overread, you can ignore it.
i notice some performance issue with the very first call of the day, that sometimes takes over 20 seconds. note only the very first call of the day, i don't know if it is only my issue or not...

that's apart EF is ok for me.

using ORM in general and EF in particular you save a lot of time developing Entities and DAL

in addictioin you can make views or stored proc if you find performance issue for complex query (also because some query are easier in sql than linq..
Sarathkumar Nallathamby 22-Jan-13 2:52am    
ya.. i have read first time call should be slow.. apart from that Is it worth to use in live sites?? Because i planned to implement on My live sites in my future.. so only...??
nrgjack 22-Jan-13 2:56am    
well i think that you shouldn't have any problem.

just in case to be sure, try to use the model and the read-write access all within a model project so in case you find performance issue becomes easier to switch to standard sql calls...


Sarathkumar Nallathamby 22-Jan-13 3:17am    
ya thank u buddy.. U were working in EF.. or with additional EF & MVC???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900