protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity <Course>().ToTable("Course"); modelBuilder.Entity <Enrollment>().ToTable("Enrollment"); modelBuilder.Entity <Student>().ToTable("Student"); InitialStoreProcedure initStore = new InitialStoreProcedure(connectionString); initStore.BuildStore("spStudentSelect", "SELECT ID, FirstMidName, LastName, EnrollmentDate FROM Student"); initStore.BuildStore("spStudentSelectByID", "SELECT ID, FirstMidName, LastName, EnrollmentDate FROM Student WHERE ID = @ID", "@ID INT"); initStore.BuildStore("spStudentInsert", "INSERT INTO Student (ID, LastName, FirstMidName, EnrollmentDate) VALUES (@ID, @LastName, @FirstMidName, @EnrollmentDate)", "@ID INT, @LastName NVARCHAR(MAX), @FirstMidName NVARCHAR(MAX), @EnrollmentDate DATETIME"); }
public DapperDatabaseContextTest() { DbInitializer.Initialize(context); //If Database had created then we begin create stores if (InitialStoreProcedure.CheckExistDB(connectionString)) { InitialStoreProcedure initStore = new InitialStoreProcedure(connectionString); initStore.BuildStore("spStudentSelect", "SELECT ID, FirstMidName, LastName, EnrollmentDate FROM Student"); initStore.BuildStore("spStudentSelectByID", "SELECT ID, FirstMidName, LastName, EnrollmentDate FROM Student WHERE ID = @ID", "@ID INT"); initStore.BuildStore("spStudentSelectTotalStudent", "SELECT COUNT(ID) FROM Student"); initStore.BuildStore("spStudentInsert", "DECLARE @StudentID INT \n IF @ID IS NULL OR @ID <= 0 \n BEGIN \n INSERT INTO Student(FirstMidName, LastName, EnrollmentDate) \n VALUES(@FirstName, @LastName, @EnrollmentDate) \n SET @StudentID = @@ROWCOUNT \n END \n ELSE \n BEGIN \n UPDATE Student SET FirstMidName = @FirstName, LastName = @LastName, EnrollmentDate = @EnrollmentDate \n SET @StudentID = @ID \n END \n SELECT @StudentID", "@ID INT = NULL, \n @FirstName NVARCHAR(50), \n @LastName NVARCHAR(50), \n @EnrollmentDate DATETIME"); initStore.BuildStore("spStudentExecNonQueryInsert", "INSERT INTO Student (FirstMidName, LastName, EnrollmentDate) VALUES (@FirstMidName, @LastName, @EnrollmentDate) Select Id from Student", "@FirstMidName NVARCHAR(MAX),@LastName NVARCHAR(MAX),@EnrollmentDate DATETIME "); initStore.BuildStore("spStudentExecNonQueryUpdate", "UPDATE Student SET FirstMidName = @FirstMidName WHERE ID = @ID", "@ID INT, @FirstMidName NVARCHAR(MAX)"); initStore.BuildStore("spStudentExecNonQueryDelete", "DELETE Student WHERE ID = @ID", "@ID INT"); } else { Console.WriteLine("Database must be created before create stored procedure."); } }