.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

using stored procedures in ado.net entity framework model

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
Hi, I have a issue, i am calling stored procedure through entity model like result=ctx.spname(parmas), i am expecting 0 or 1 as a result after the execution of sp, but its returning unknown values like 178 for number records. Please suggest what went wrong Thanks

View Complete Post

More Related Resource Links

Entity Framework and stored procedures with OUTPUT parameters (suggest API)

EF does handle stored procedures with OUTPUT parameters, but the generated methods are not the easiest to work with or safest you could ask for. The ObjectParameter objects you have to create, pass to the method and extract the value from are not type checked and reallyObjectParameter nameParam = new ObjectParameter( "Name", typeof(string)); ObjectParameter ageParam = new ObjectParameter( "Age", typeof(int)); context.GetPersonsNameAndAge( personId, nameParam, ageParam); string name = Convert.IsDBNull(nameParam.Value) ? null : (string)nameParam.Value; int? age = Convert.IsDBNull(ageParam.Value) ? null : (int?)ageParam.Value; is not what I would want to have to write.The ObjectParameter objects do make some sense for stored procedures that return both a resultset and some OUTPUT parameters, because in that case the OUTPUT parameters are only available after the resultset has been consumed and therefore you need some objects that will be populated after the ObjectResult<...> gets processed but for the stored procedures that do not return any resultset, there is no reason not to create the ObjectParameter objects within the method and extract the values there as well. So that the procedure above may be called asstring name; int? age; context.GetPersonsNameAndAge( personId, out name, out age); Things are not so simple for procedures returning both. I'm

Never SELECT * from Entity Framework called Stored Procedures


The Entity Framework can help us create an efficient Data Access Layer or a horribly inefficient one. 

It's worth mentioning that if we use Entity Framework to call a stored procedure that returns a database derived Entity using a SELECT * (star), we will have that horribly inefficient DAL.  Of course, as we've been told for years, SELECT * is 99.0% wrong with 1% for those dynamic field cases.  With EF calling a stored procedure, it's really wrong.

SQL Profiler will show us that the store procedure does return all records as fast as it can, barring a badly written stored procedure or low SQL server memory.  Entity Framework unfortunately does not assume all fields have returned.  EF then calls back with the defined primary key for each record.  This means that for a stored procedure that returns 1 million rows in one connection, actually returns 2 million rows with 2 million and one database server calls / connections from the application layer.  Try it on a 3 record table sometime to see that it calls SQL Server 4 times for three rows even when we use a stored procedure.  Enterprise DBA's will complain as they should.  If there is an obscure switch to avoid this, I

Entity Framework 4.0 Dynamic Data - stored procedure


I'm using Dynamic Data and have created a custom List.aspx page.  I simply want to populate the grid with a stored procedure.  I've seen some posts about doing this with a LinqDataSource but not an EntityDataSource.  Does someone have an example or a different way of doing this?  Thanks.

Entity Model- Add Function Import - selected stored procedure returns no columns

I am using stored procedures returns columns from pivot table generated dynamically "Execute (@PivotTableSQL)".So the resultset columns cannot be identified. Please let us know how to add function import and Get Column information(create complex Type). Thanks in advance. My stored procedure is alter PROCEDURE spGetQuestGrid( @QID as int)ASBEGIN SET NOCOUNT OFF SET FMTONLY OFF  Declare @optId varchar(10) set @optId = (select DISTINCT Optid from  QuestOptions where  QID = @QID)    DECLARE @PivotColumnHeaders VARCHAR(MAX) SELECT @PivotColumnHeaders =  COALESCE(@PivotColumnHeaders + ', [' + cast(Caption as varchar) + ']' ,  '[' + cast(Caption as varchar)+ ']' ) FROM OptionsDetail where OptId = @optId  DECLARE @PivotTableSQL NVARCHAR(MAX)  SET @PivotTableSQL = 'select * from  ( select  Caption,Optid  from OptionsDetail ) as dt PIVOT  ( min(Optid) FOR Caption IN ( '+ @PivotColumnHeaders + '))as pt'     Execute (@PivotTableSQL)  END 

How to Bind Selective Columns from Stored Proc to Gridview using the entity framework


Hi Guys,

I have this entity model>> http://img840.imageshack.us/img840/306/schemaj.jpg and I would like to bind  a list  which consists of: employee's

  • emloyee_firstname(employees table) + employee_lastname(employees table)
  • employee's extension(employee_extension table)
  • deparment name(departments table)

to my gridview. I already created my stored procedure

    Concat(employees.employee_firstname," ",employees.employee_lastname) as name
    , extensions.extension_number
    , departments.department_description
    INNER JOIN employees 
        ON (employee_extensions.employee_id = employees.employee_id)
    INNER JOIN extensions 
        ON (employee_extensions.extension_id = extensions.extension_id)
    INNER JOIN departments 
        ON (employees.department_id = departments.department_id)

But my problem is, i don't know how to bind it since i don't have an entity that contains the employee's name, extension# and departments name. Do I need to create a custom class that consists of said columns? or is their a proper way to do this? I'

Entity Framework - stored procedure mapping, excecuting SP with float parameters separated by commas



Im using Entity framework with POCO entity generator template + SQL Server. I have mapping to stored procedure that takes two floats as input.

After executing function from code with two doubles as parameters: 1.23 and 4.56, SQL Profiler shows:

exec storedProcedureName @arg1 = 1,23, @arg2= 4,56

This is causing an error because it looks like that stored procedure takes 4 arguments, but it should take only two and there should be dots insted of commas in these floats.

My SQL Server collation is SQL_Latin1_General_CP1_CI_AS. I tried to set:

           Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
           Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

in DataContext Constructor, and di

MVVM and Entity Framework - where is the Model part?



I am using Entity Framework to connect to MS SQL (Azure). I have a WPF application, and I am using MVVM. But...where is my Model layer? Right now I have made the 'traditional' Model layer, which then translates the Entity Framework into new objects. That works, - but I am missing out of all the implicit benefit of Entity Framework! If I pulled a collection directly from the Entity Framework to the the ViewModel, I could then work on the collection (add, delete, update) and then just run SaveChanges() on the connection and it was a done deal. But right now it is the object in the Model layer that I work on, and then in this object I have to add, delete or update another object in the database through Entity Framework.

To get the benefits, should I just skip all the extra objects in my Model layer and make the Entity Framework a part of the Model Layer (although it is also a data access layer, of sorts)? Or is there a way to pass the Entity Framework objects through the Model layer smoothly so I still maintain the wonderful SaveChanges() functionality?



Dynamic Data using Code First Entity Framework Model


I have used Dynamic Data before using LinqToEntity where my Entity model used the Data First model and the GUI.  Now I am trying to use the Code First model witht he Entity CTP 4.  I have my model created and created a new Dynamic Data site.  I read that I need to replace the default RegisterContext call:

DefaultModel.RegisterContext(typeof(PriceLoaderContext), new ContextConfiguration() { ScaffoldAllTables = true });


DefaultModel.RegisterContext(new DomainModelProvider(typeof(PriceLoaderContext)), new ContextConfiguration() { ScaffoldAllTables = true }); 

When I search further on DomainModelProvider, I find that it is part of the WCF RIA. Is this correct? Is this what I need for this to work? Has anyone else done this and got it to work?


Entity Framework - Automatically filtering where IsDeleted in model-first scenario


I am using a model-first development approach with Entity Framework, meaning I make schema changes in a designer in Visual Studio, and use the Generate Database from Model command to generate a a SQL script for creating all of the appropriate database tables which match the model.

I am trying to figure out the best (any) approach to automatically filtering on IsDeleted = false with my various entities. I don't want to have to constantly be adding an IsDeleted = false condition to all of my queries, and lazy loading, etc... So for example, ideally I would like to be able to write the following code, and know that it is only return entities which are not logically deleted:

var people = context.People;

So I have attempted to implement a few different approaches to no avail:

1.) Within the designer, add a condition to each entity with IsDeleted = 0. The problem with that is that EF only supports having one mapping per property. If I have a condition that refers to

Issue while creating a BCS entity in visual studio for SQL stored procedures


Hi Everyone,

                  I have an issue while creating an entity in Visual studio for SQL stored procedures.I have two input parameters startdate and enddate as datetime datatypes in the stored procedures.I have added two input parameters startdate and enddate in the Readlist and ReadItem methods and created two filter descriptors startdate and enddate of "comparison" type and related these to their respective input parameters.

                 In my readlist and readitem methods I have used LINQ TO SQL query to query the SP.When I debug the program,I am receiving an error message-->remote procedure cannot be debugged.Also my parameters are not being passed to the SP.Any help is appreciated..also if any one has step by step approach,that helps me a lot.

entity framwork with stored prcedure vs entity framwork without stored procedures


I am new to entity framwork , it is really very good , but I want to know what is the differance between using entity framwork with stored procedure or without stored procedure , which one the faster and what is the benifits for using stored procedures with entity framwork

Trying to use stored procedure in Entity Framework


I have a aspx page that only has a button and a button click event.

My code behind looks like this

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommerceModel;

public partial class test : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        using (CommerceEntities context = new CommerceEntities())
                UBOtest myRecord = new UBOtest
                    dataA = "Tina",
                    dataB = "Feeney"
            catch (Exception ex)

This code works fine if I have no insert stored procedure mapped to Table UBOtest in the EntityDataModel.However, when I map the stored procedure to the EntityDataModel and add UBOtestinsert I get an error that reads "An error occured while updating the entries. See the inner exception for details.">/P>

Then the innerException message is "Invalid object name 'UBOtes

Partial update with stored procedure in Entity Framework 4


How do I use a stored procedure to change one or more (but not all) fields of a entity in EF4? I have a stored procedure "ChangePassword" taking a username and and a password as parameters and a User entity containing properties for Username and Password as well as other properties. I want to be able to use this stored procedure from a function to update the password from a function in one of my repositories. How to do this?

How to map an Entity framework model to a table name dynamically


I am working in MVC 3 with entity frame work so I am using List, create, edit and details page by razor templates of csHTML5.

But I have found one problem while creating a templates from my company model which Company table available in my existing database which I cannot change.

So all related controller and View has been created along with context, but Problem is comes that created entity framework structure is expected tables “Companies” but in my case I have table with company. Below

Data Points: Demystifying Entity Framework Strategies: Model Creation Workflow


The Entity Framework now includes more ways than ever to create a conceptual model, starting first with just your code, a model created with the visual designer, or a legacy database. We help you choose which one's right for you.

Julie Lerman

MSDN Magazine May 2011

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend