You must Sign In to post a response.
  • Category: .NET

    Which is best Between Entity Framework And Stored Procedure ?

    Hi Friends,

    Please tell me

    Which is best Between Entity Framework And Stored Procedure ?

    for ERP Application In Asp.net MVC
  • #768400
    Hi,

    Difference between Entity Framework and Stored Procedure is chosen based on your requirement.

    Stored Procedure:
    Encapsulate multiple statements as single transactions using stored procedure.
    Implement business logic using temp tables.
    Better error handling by having tables for capturing/logging errors.
    Parameter validations / domain validations can be done at database level.
    Control query plan by forcing to choose index.
    Use sp_getapplock to enforce single execution of procedure at any time.

    Entity Framework:
    LINQ to SQL and EF queries will be "untunable" because, even if you discover a performance problem, you can't change the underlying API code to produce the exact SQL query that you want. There's too many layers of abstraction to change it.

    T-SQL is a declarative language, allowing you the ability to rewrite queries for better performance.

    EF 5 simplifies this part a bit with auto-compiled LINQ Queries, but for real high volume stuff, you'll definitely need to test and analyze what fits best for you in the real time world.

    Thanks,
    Mani

  • #768401
    Entity Framework has the ability to automatically build native commands for the database based on your LINQ. This code snippet is useful to create Stored Procedure
    CREATE PROCEDURE [dbo].[GetCoursesByStudentId]
    @StudentId int = null
    AS
    BEGIN
    SET NOCOUNT ON;

    select c.courseid, c.coursename,c.Location, c.TeacherId
    from student s
    left outer join studentcourse sc on sc.studentid = s.studentid
    left outer join course c on c.courseid = sc.courseid
    where s.studentid = @StudentId
    END

  • #768406
    Hi,

    Performance point of view, stored procedure are faster because you can send parameters to it and implement business logic using temp tables.
    Using Entity Framework, you can issue a single LINQ query that will retrieve all the data in a single call and fill various tables at a time. But performance and memory management degrades.


Sign In to post your comments