LINQ to SQL NullReferenceException on SubmitChanges
I’ve been busy working on some LINQ to SQL (formerly DLINQ) apps that have been going well bar a NullReferenceException thrown at me from deep in the bowels of LINQ and it’s change tracker. A cursory glance in debug showed none of the properties that represent columns were null…
The null was actually a collection property that represented a one-to-many relationship that was automatically created using the foreign key constraints in the database. Normally this is set to an empty EntitySet however I was failing to call the default constructor from my new useful constructor.
The moral of the story is always call the default constructor with this(), especially when extending generated code. So much for persistence ignorance.
public partial class Invoice {
public Invoice(int number) : this() {
this.number = number;
}
}
[)amien
5 responses