dhiraj sakariya

dhiraj sakariya

  • 1.5k
  • 166
  • 1.2k

Add rows and column at runtime and update values to database

Jan 24 2017 7:09 AM

Hi there, I have created Entity models. I would like to design a xaml in wfp to insert and update records like spreadsheet. i have attached sample entities and screenshot. Here Column represents : Subject and total Marks Rows represents : class Section and students Cell is to update marks objects in that particular subject by students

How can I add Subject(column) at run time and save it to database?

How can I Standard, ClassSection and student and their mark (Rows) in grid and save it to database?

Can anyone suggest the approach?

  1. Below are the Models:  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.ComponentModel.DataAnnotations;  
  5. using System.Data.Entity;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9.   
  10. namespace School.Model  
  11. {  
  12.   
  13.     public class SchoolContext : DbContext  
  14.     {  
  15.         public DbSet<Standard> Standards { getset; }  
  16.         public DbSet<Subject> Subjects { getset; }  
  17.         public DbSet<ClassSection> ClassSections { getset; }  
  18.         public DbSet<Student> Students { getset; }  
  19.   
  20.         public DbSet<Result> Results { getset; }  
  21.     }  
  22.    public  class Standard  
  23.     {  
  24.         [Key]  
  25.         public int Id { getset; }  
  26.         public string Name { getset; }  
  27.   
  28.         public ICollection<Subject> Subjects { getset; }  
  29.         public ICollection<ClassSection> ClassSections { getset; }  
  30.   
  31.     }  
  32.   
  33.     public class Subject  
  34.     {  
  35.         [Key]  
  36.         public int Id { getset; }  
  37.   
  38.         public string Name { getset; }  
  39.   
  40.         public int TotalMarks { getset; }  
  41.   
  42.         public int? StandardId { getset; }  
  43.   
  44.         public virtual Standard Standard { getset; }  
  45.   
  46.         public ICollection<Result> Results { getset; }  
  47.     }  
  48.   
  49.     public class ClassSection  
  50.     {  
  51.         [Key]  
  52.         public int Id { getset; }  
  53.   
  54.         public string Name { getset; }  
  55.   
  56.   
  57.         public int? StandardId { getset; }  
  58.   
  59.         public virtual Standard Standard { getset; }  
  60.         public ICollection<Student> Students { getset; }  
  61.     }  
  62.   
  63.     public class Student  
  64.     {  
  65.         [Key]  
  66.         public int Id { getset; }  
  67.   
  68.         public string Name { getset; }  
  69.   
  70.   
  71.         public int? ClassSectionId { getset; }  
  72.   
  73.         public virtual ClassSection ClassSection { getset; }  
  74.         public ICollection<Result> Results { getset; }  
  75.     }  
  76.   
  77.     public class Result  
  78.     {  
  79.         [Key]  
  80.         public int Id { getset; }  
  81.   
  82.         public int SubjectId { getset; }  
  83.         public int StudentId { getset; }  
  84.   
  85.         public int ObtainedMarks { getset; }  
  86.   
  87.         public virtual Subject Subject { getset; }  
  88.         public virtual Student Student { getset; }  
  89.   
  90.     }  
  91. }  

Answers (3)