Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET entity
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 21-Jan-13 2:46am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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
  Permalink  
v2
Comments
sarathkumarnallathambi at 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..?
katanakensei at 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..
sarathkumarnallathambi at 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...??
katanakensei at 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...
 

sarathkumarnallathambi at 22-Jan-13 3:17am
   
ya thank u buddy.. U were working in EF.. or with additional EF & MVC???
katanakensei at 22-Jan-13 3:19am
   
yep i was thinking about that EF+MVC
 
BUT
 
i have no experience in MVC so i can't give u hints in that case
sarathkumarnallathambi at 22-Jan-13 4:20am
   
ya. ok.. Me too working in EF only.. Not EF+MVC .. Anyway thanks for ur reply.. Keep Rocking .....
sarathkumarnallathambi at 23-Jan-13 0:46am
   
OK Man.. But i saw Bl tool kit have lead performance than EF.... Which one u ll suggest??
sarathkumarnallathambi at 22-Jan-13 0:05am
   
Hi wat the use of using System.Data.Objects; . And its working to me but its just like normal ado...

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,567
3 Zoltán Zörgő 3,386
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100