:
CRUD ::
Entity Framework LINQ to Entities Entity SQL, , . . , // .
, , DbContext. , DDL context.SaveChanges().
- sp_InsertStudentInfo
- sp_UpdateStudent
sp_DeleteStudent .
CREATE PROCEDURE [dbo].[sp_InsertStudentInfo]
@StandardId int = null,
@StudentName varchar
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [SchoolDB].[dbo].[Student]([StudentName],[StandardId])
VALUES(@StudentName, @StandardId)
SELECT SCOPE_IDENTITY() AS StudentId
END
CREATE PROCEDURE [dbo].[sp_UpdateStudent]
@StudentId int,
@StandardId int = null,
@StudentName varchar
AS
BEGIN
SET NOCOUNT ON;
Update [SchoolDB].[dbo].[Student]
set StudentName = @StudentName,StandardId = @StandardId
where StudentID = @StudentId;
END
CREATE PROCEDURE [dbo].[sp_DeleteStudent]
@StudentId int
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM [dbo].[Student]
where StudentID = @StudentId
END
, EDM , " " , "" .

,

, EDM, "" " ", :

,. , . sp_InsertStudentInfo Insert, :

sp_InsertStudentInfo StudentId. , Student Entitys StudentID, :

Insert, Update Delete, :

, , . "" "" , :

, , :
using (var context = new SchoolDBEntities())
{
Student newStudent = new Student() { StudentName = "New Student using SP"};
context.Students.Add(newStudent);
context.SaveChanges();
newStudent.StudentName = "Edited student using SP";
context.SaveChanges();
context.Students.Remove(newStudent);
context.SaveChanges();
}
SaveChanges():
exec [dbo].[sp_InsertStudentInfo] @StandardId=NULL,@StudentName='New Student using SP'
go
exec [dbo].[sp_UpdateStudent] @StudentId=47,@StandardId=NULL,@StudentName='Edited student using SP'
go
exec [dbo].[sp_DeleteStudent] @StudentId=47
go
Note . After a context call to SaveChagnes, after adding a new student, it assigns the StudentID property to the StudentID property of the Student object, because sp_InsertStudentInfo returns StudentId. It is necessary to use this object of the object for further operation.

See here for more details. practically.
source
share