Introduction

This article shows how to do table splitting and update data operations.

SQL Server table structure


Create an ASP.Net Web Application as in the following:


Set up Entity Framework as in the following:


Cut columns from the employee entity as in the following:


Paste them into the EmployeeDetails entity as in the following:


Add an association between Employee and EmployeeDetails as in the following:


Referential constraints


Webform1.aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Table_Splitting_Update_Data.WebForm1" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id="form1" runat="server">
  9. <div>
  10. <asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button1_Click" />
  11. </div>
  12. </form>
  13. </body>
  14. </html>

Webform1.aspx.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace Table_Splitting_Update_Data
  8. {
  9. public partial class WebForm1 : System.Web.UI.Page
  10. {
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. }
  14. protected void Button1_Click(object sender, EventArgs e)
  15. {
  16. EmployeeDBEntities empContext = new EmployeeDBEntities();
  17. int empId = 1;
  18. var emp = empContext.Employees.Where(a => a.EmpId.Equals(empId)).SingleOrDefault();
  19. emp.FirstName = "Jonny";
  20. emp.EmployeeDetail.Email = "[email protected]";
  21. empContext.SaveChanges();
  22. }
  23. }
  24. }

The following is the output of the application:


Before performing update operation:

After performing update operation:

Summary

In this article we saw how to do table splitting and update data operations.
Happy coding!