0

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????...}
};
4
  • Are you confused about initializer syntax because of nesting? Commented Jan 16, 2017 at 12:30
  • Hi Ankit. I think so. Any advice? Commented Jan 16, 2017 at 13:25
  • 1
    Jerome, please include code for the History, Family classes. Commented Jan 16, 2017 at 13:37
  • I believe this has nothing to do with Visual Studio or the Entity Framework Commented Jan 16, 2017 at 15:49

1 Answer 1

1

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
            //...
        }
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.