Click here to Skip to main content
Sign Up to vote bad
good
See more: C#3.0ASP.NETentity
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 - 1:46


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...
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  
Comments
sarathkumarnallathambi - 21 Jan '13 - 23:35
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 - 22 Jan '13 - 2:47
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 - 22 Jan '13 - 2:52
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 - 22 Jan '13 - 2:56
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 - 22 Jan '13 - 3:17
ya thank u buddy.. U were working in EF.. or with additional EF & MVC???
katanakensei - 22 Jan '13 - 3:19
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 - 22 Jan '13 - 4:20
ya. ok.. Me too working in EF only.. Not EF+MVC .. Anyway thanks for ur reply.. Keep Rocking .....
sarathkumarnallathambi - 23 Jan '13 - 0:46
OK Man.. But i saw Bl tool kit have lead performance than EF.... Which one u ll suggest??
sarathkumarnallathambi - 22 Jan '13 - 0:05
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 414
1 Arun Vasu 223
2 OriginalGriff 190
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


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