c# - leaving entity framework entity properties empty when they're not applicable -


i'm afraid might @ risk of being closed being opinion-based but...

i have entity

namespace rota.domain.entities {     public class shift     {         [key]         public int shiftid { get; set; }          [required]         [stringlength(50)]         public string name { get; set; }          public string starttime { get; set; }         public string endtime { get; set; }         public timespan shiftlength {                         {                 return datetime.parse(endtime).subtract(datetime.parse(starttime));             }         }          public virtual icollection<employeeshift> employeeshifts { get; set; }     } } 

what wondering is, whether ok leave of fields intentionally blank, examble if starttime/endtime not applicable e.g. if person on holiday, wouldn't require start or end times.

currently initaliser file looks this:

protected override void seed(efdbcontext context)         {             list<shift> shifts = new list<shift>()             {                 new shift { name = "early", starttime = "08:00", endtime = "16:00" },                 new shift { name = "normal", starttime = "9:00", endtime = "17:00" },                 new shift { name = "late", starttime = "10:00", endtime = "18:00" },                 new shift { name = "holiday" },                 new shift { name = "sick" }             };             shifts.foreach(s => context.shift.add(s));             context.savechanges();          } 

it doesn't feel right keeping these blank, have no idea would/could differently.

is ok leave entity properties empty when they're not applicable

you might want use timespan instead of string, since can calculations more timespans, can nullable if don't want have values them. holiday or sickleave should "full date" event, 00:00 24:00. kinda depends on how want model data , going them.

and answer question, yes, can have null values entities long on intention , handle them when using entities. example have nullable boolean field user setting (allow contact email etc) having null mean not asked user , should handle "no", having value mean user have saved settings , value should used is.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -