0
我有我使用一週中的旗天爲真/假值的原子類。序列化類的實體數據庫存儲
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);
}
}
}
我想將這個使用實體作爲一個列存儲。我有一個POCO,看起來像這樣:
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();
}
}
這裏的問題是,當我訪問DaysOfWeek財產,我不能設置一個值。
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;
我相信我所需要的是一個ObservableCollection事件,但搜索的例子後,我不完全知道如何實現它。我是否修改我的實體POCO SSRS_Subscription來添加它?任何提示或提示如何更好地做到這一點將不勝感激。