I have an atomic class I'm using to flag days of the week as true/false values.
public class DaysOfWeek
{
public bool Sunday { get; set; }
public bool Monday { get; set; }
public bool Tuesday { get; set; }
public bool Wednesday { get; set; }
public bool Thursday { get; set; }
public bool Friday { get; set; }
public bool Saturday { get; set; }
public bool this[string day]
{
get
{
return (bool)GetType().GetProperty(day).GetValue(this, null);
}
set
{
GetType().GetProperty(day).SetValue(this, value);
}
}
}
I'd like to store this using Entity as a single column. I have a POCO that looks like this:
public class SSRS_Subscription
{
[Key]
public Guid id { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public Recurrence RecurrencePattern { get; set; }
public DateTime StartTime { get; set; }
public int? MinuteInterval { get; set; }
public int? DaysInterval { get; set; }
public int? WeeksInterval { get; set; }
[NotMapped]
public DaysOfWeek DaysOfWeek
{
get
{
return SerializeHelper.DeserializeJson<DaysOfWeek>(internalDaysOfWeek);
}
set
{
internalDaysOfWeek = SerializeHelper.SerializeJson(value);
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Column("DaysOfWeek")]
public string internalDaysOfWeek { get; set; }
public SSRS_Subscription()
{
DaysOfWeek = new DaysOfWeek();
}
}
The issue here is that when I access the DaysOfWeek property, I cannot set a value.
var testSub = new SSRS_Subscription();
testSub.DaysOfWeek.Friday = true;
// testSub.DaysOfWeek.Friday stays false (the default value)
// However doing this sets the correct value...
var tmpDaysOfWeek = testSub.DaysOfWeek;
tmpDaysOfWeek.Friday = true;
testSub.DaysOfWeek = tmpDaysOfWeek;
I believe what I need is an ObservableCollection event, but after searching for examples, I'm not exactly sure how to implement it. Do I modify my Entity POCO SSRS_Subscription to add it? Any hints or tips on how to do this better would be greatly appreciated.