This question is locked. New answers and comments are not allowed.
Previously in forward-only mapping, I would have a private field and public property for a relationship:-
Now with the Fluent API, if I take the example here I would do away with the field, and have just the property:-
Which a) forces me to use the set accessor (which I don't need), and b) takes away the initialization of the list.
The example in the link above defines a one-to-many in just this way, however in the usage example it is used...
Which is how I previously used it (as a managed list). Trying to use this method now throws a NullReferenceException because the Orders property the customer is not initialised if it is empty.
I can't find any info on the correct way to initialise this using the new method.
Thanks in advance for any help that can be provided
public class Customer{ private IList<Order> orders = new List<Order>(); public IList<Order> Orders { get { return orders; } } ...Now with the Fluent API, if I take the example here I would do away with the field, and have just the property:-
public class Customer{ public IList<Order> Orders { get; set; } ...Which a) forces me to use the set accessor (which I don't need), and b) takes away the initialization of the list.
The example in the link above defines a one-to-many in just this way, however in the usage example it is used...
// like this...Order.Customer = customer;// instead of...Customer.Orders.Add(order);Which is how I previously used it (as a managed list). Trying to use this method now throws a NullReferenceException because the Orders property the customer is not initialised if it is empty.
I can't find any info on the correct way to initialise this using the new method.
Thanks in advance for any help that can be provided