Abbiamo deciso di utilizzare per il nostro progetto l’Entity Framework e di far uso della tecnica del code first per generare il Nostro modello.

Ecco la prima versione:

   1: using System;

   2: using System.Collections.Generic;

   3: using System.Linq;

   4: using System.Web;

   5: using System.ComponentModel.DataAnnotations;

   6: using System.ComponentModel.DataAnnotations.Schema;

   7:  

   8: namespace BugTracker.Models

   9: {

  10:     [Table("Bugs")]

  11:     public class Bug

  12:     {

  13:         [Key]

  14:         public int BugId { get; set; }

  15:  

  16:         public string Title { get; set; }

  17:  

  18:         public int ProjectId { get; set; }

  19:         [ForeignKey("ProjectId")]

  20:         public Project Project { get; set; }

  21:  

  22:         public Int32? AreaId { get; set; }

  23:         [ForeignKey("AreaId")]

  24:         public Area Area { get; set; }

  25:  

  26:         public int? PriorityId { get; set; }

  27:         [ForeignKey("PriorityId")]

  28:         public Priority Priority { get; set; }

  29:  

  30:         public int StatusId { get; set; }

  31:         [ForeignKey("StatusId")]

  32:         public Status Status { get; set; }

  33:  

  34:  

  35:         public int? AssignedUserId { get; set; }

  36:         [ForeignKey("AssignedUserId")]

  37:         public virtual User AssignedUser { get; set; }

  38:         public DateTime? AssignedDate { get; set; }

  39:  

  40:  

  41:         public int InsertUserId { get; set; }

  42:         [ForeignKey("InsertUserId")]

  43:         public virtual User InsertUser { get; set; }

  44:         public DateTime InsertDate { get; set; }

  45:  

  46:         public int? LastUpdateUserId { get; set; }

  47:         [ForeignKey("LastUpdateUserId")]

  48:         public virtual User UpdateUser { get; set; }

  49:  

  50:         public Boolean FlagDeleted { get; set; }

  51:  

  52:         public virtual ICollection<Comment> Comments { get; set; }

  53:     }

  54:  

  55:     [Table("Comments")]

  56:     public class Comment

  57:     {

  58:  

  59:         public int CommentId { get; set; }

  60:  

  61:         public int BugId { get; set; }

  62:         [ForeignKey("BugId")]

  63:         public Bug Bug { get; set; }

  64:  

  65:         public string Description { get; set; }

  66:  

  67:         public int InsertUserId { get; set; }

  68:         [ForeignKey("InsertUserId")]

  69:         public User InsertUser { get; set; }

  70:         public DateTime InsertDate { get; set; }

  71:  

  72:         public int? LastUpdateUserId { get; set; }

  73:         [ForeignKey("LastUpdateUserId")]

  74:         public User lastUpdateUser { get; set; }

  75:         public DateTime? LastUpdateDate { get; set; }

  76:         public Boolean FlagDeleted { get; set; }

  77:  

  78:     }

  79:     //[Table("Attachment")]

  80:     //public class Attachment { 

  81:     //}

  82:  

  83:     [Table("Projects")]

  84:     public class Project

  85:     {

  86:         [Key]

  87:         public int ProjectId { get; set; }

  88:         public string Name { get; set; }

  89:         public string Description { get; set; }

  90:  

  91:         public virtual ICollection<Bug> Bugs { get; set; }

  92:         public virtual ICollection<Area> Areas { get; set; }

  93:  

  94:     }

  95:  

  96:     [Table("Areas")]

  97:     public class Area

  98:     {

  99:         [Key]

 100:         public int AreaId { get; set; }

 101:         public int ProjectId { get; set; }

 102:         [ForeignKey("ProjectId")]

 103:         public Project Project { get; set; }

 104:         public string Name { get; set; }

 105:         public string Description { get; set; }

 106:     }

 107:  

 108:     [Table("Priorites")]

 109:     public class Priority

 110:     {

 111:         [Key]

 112:         public int PriorityId { get; set; }

 113:         [MaxLength(10), MinLength(5)]

 114:         public string Name { get; set; }

 115:         public string Value { get; set; }

 116:     }

 117:  

 118:     [Table("Status")]

 119:     public class Status

 120:     {

 121:         [Key]

 122:         public int StatusId { get; set; }

 123:         public string Name { get; set; }

 124:         public string Value { get; set; }

 125:     }

 126:     [Table("Users")]

 127:     public class User

 128:     {

 129:         [Key]

 130:         public int UserId { get; set; }

 131:  

 132:         public string FirstName { get; set; }

 133:         public string LastName { get; set; }

 134:         public string Username { get; set; }

 135:         public string Password { get; set; }

 136:         public bool IsAdmin { get; set; }

 137:  

 138:         public virtual ICollection<Bug> InsertedBugs { get; set; }

 139:         public virtual ICollection<Bug> UpdatedBugs { get; set; }

 140:         public virtual ICollection<Bug> AssignedBugs { get; set; }

 141:  

 142:         public virtual ICollection<Comment> InsertedComments { get; set; }

 143:         public virtual ICollection<Comment> UpdatedComments { get; set; }

 144:  

 145:     }

 146:  

 147:  

 148: }

Per incominciare dovrebbe andare bene Occhiolino

Altri Articoli

ASP.NET Core Middleware
views 455
"Middleware are software components that are assembled into an application pipeline to handle requests and responses. Each component chooses whether t...
ASP.NET Core Project Start Up
views 237
Pubblicato nella sezione wiki un nuovo tutorial su ASP.NET Core: ASP.NET Core Project Start Up. Questo tutorial spiega passo passo la creazione di un...
Creare una Applicazione ASP.NET Core con CLI e Vis...
views 373
La nuova versione ASP.NET CORE è ormai arrivata alla RC2 (Release Candidate 2), possiamo dire che i tempi sono maturi e nonostante le continue evoluzi...
Benvenuto ASP.NET Core 1.0
views 146
Lo scorso 19 gennaio Scott Hanselman ha annunciato sul suo blog la scelta di modificare il nome della prossima versione di ASP.NET, nel giro di una an...