I just started working through the first tutorial in the "OpenAccess Made Easy" book and I'm running into a problem already... must be something simple. I am getting NullReferenceException (Object reference not set to an instance of an object.) at the line "customer.Orders.Add(order);". Not sure why. The tables in the DB get created just fine, but then I hit this exception. It's a simple console application. Here is my code:
class Program
{
static void Main(string[] args)
{
IObjectScope scope = ObjectScopeProvider1.ObjectScope();
scope.Transaction.Begin();
Customer customer = new Customer();
customer.CustomerName =
"Bob";
customer.CustomerNumber = 123;
Order order = new Order();
order.OrderNumber = 1;
customer.Orders.Add(order); // <--- exception happens here.
scope.Add(customer);
scope.Transaction.Commit();
}
}
[Telerik.OpenAccess.Persistent]
public class Customer
{
private int customerNumber;
public int CustomerNumber
{
get { return customerNumber; }
set { customerNumber = value; }
}
private string customerName;
public string CustomerName
{
get { return customerName; }
set { customerName = value; }
}
private IList<Order> orders;
public IList<Order> Orders
{
get { return orders; }
set { orders = value; }
}
}
[Telerik.OpenAccess.
Persistent]
public class Order
{
private int orderNumber;
public int OrderNumber
{
get { return orderNumber; }
set { orderNumber = value; }
}
}
thanks in advance for your help.