I have a generic class TimeSeries<T> which contains a list of generic state variables State<T>. State<T> contains the state at a certain time.
public class TimeSeries<T>
{
[Key]
public int ID { get; set; }
public List<State<T>> States { get; set; }
}
public class State<T>
{
[Key]
public int StateID { get; set; }
public DateTime Date { get; set; }
public T State { get; set; }
}
Furthermore, I have two classes IntClass and FloatClass, both of which contain a time series, but of different types. To obtain two tables for TimeSeries, where one has a foreign key pointing to IntClass and the other one has a foreign key pointing to FloatClass, I have derived two more classes from TimeSeries<T>, each containing a property for the foreign key.
public class IntTimeSeries : TimeSeries<int>
{
public int IntClassID{ get; set; }
}
public class FloatTimeSeries : TimeSeries<float>
{
public int FloatClassID{ get; set; }
}
IntClass and FloatClass contain an instance of the derived classes:
public class IntClass
{
[Key]
public int ID { get; set; }
public IntTimeSeries TimeSeries { get; set; }
}
public class FloatClass
{
[Key]
public int ID { get; set; }
public FloatTimeSeries TimeSeries { get; set; }
}
This approach generates among others the tables State<int> and State<float>. These have the (auto-generated) foreign keys IntClassID and FloatClassID, respectively. If I annotate StateID with [Key] as I have done here, then that is of course the primary key.
What I want, however, is that the primary keys are the composites (Date, IntClassID) and (Date, FloatClassID), respectively. I need this because I sometimes need to update the values from a second database where I have only reading permission. Is this possible?