Reputation:
I've got a small project and just after some advice on how to seed and initialize some data. The two main classes are Client and History. There is a one-to-one relationship between these. Within History in addition to properties there are also a number of other classes eg. Family class.
So in the initializer class I can set the value to the properties of the history class but I can't figure out how to access and set the value of the properties within the Family object (which is itself a separate table with it's own ID and the HistoryID as a foreign key.)
var historys = new List<History>
{
new History {ClientID=2, Hopc="The dog ate my homework"},
new History {ClientID=1, Hopc="The cat ate the dog"}
// new History {ClientID=3, Family????...}
};
Upvotes: 0
Views: 45
Reputation: 2518
List of history could be initlialized like this:
var historys = new List<History>
{
new History {ClientID=2, Hopc="The dog ate my homework"},
new History {ClientID=1, Hopc="The cat ate the dog"}
new History
{
ClientID=3,
Family = new Family
{
Property1 = "value1",
Property2 = "value2
//...
}
}
};
Upvotes: 1