LINQ InsertOnSubmit: NullReferenceException
Actually it's better to add a call to your constructor that also calls the generic constructor such as:
public IP(string address) : this() {...}
Got it.
Rather than creating a class that inherits from the DataContext's class, I extend the DC class itself with a partial class in the Business Logic layer. From there I can add whatever constructors and methods I wish.
In this case, it is neccessary to copy the code from the existing (auto-generated) constructor:
public IP(string address) {Address = address;Domain = "";Notes = "";FirstAccess = DateTime.Now;LastAccess = DateTime.Now;this._Sessions = new EntitySet<Session>(new Action<Session>(this.attach_Sessions), new Action<Session>(this.detach_Sessions));OnCreated(); }
Not sure what's in that OnCreated handler, but it seems to be doing the work that boned me earlier. Works fine now :)
Since the default constructor already initializes base(), this._Sessions and runs the OnCreated method, all you need to do in your extended constructor is this:
public IP(string address) : this(){ Address = address; Domain = ""; Notes = ""; FirstAccess = DateTime.Now; LastAccess = DateTime.Now;}