SaveChanges() on my EFv4 POCO context suddenly stopped working. It issues an error "Cannot insert NULL value into column 'postalcode' of table Clients"
Client
entity contains a reference to PostCode
(properties postalcode
, postname
) entity.
PostCode reference is not null and so aren't it's properties. My Client
entity is referenced from the Document
entity.
Here's the code
public void Add(Document instance)
{
// Firm reference
instance.Firm =
(from f in _ctx.Firms
where f.firm_id.Equals(AppState.FirmId)
select f).First();
// Client reference (lazy loading is in place and works)
if (instance.client_id != null)
instance.Client = (from c in _ctx.Clients
where c.client_id.Equals(instance.client_id)
select c).First();
instance.document_id = Guid.NewGuid();
_ctx.Documents.AddObject(instance);
_ctx.Documents.SaveChanges();
}
The thing is, AddObject()
works but SaveChanges() fails. I've inspected the Document instance, Client reference and Client's PostCode reference all over and through, all the values are there (which also proves that lazyloading is in place and working) but save doesn't happen.
Looking for ideas what could I've missed..