Wiki Link: [discussion:1979]
Private entitykey and reference setters 

Jul 2 2009 at 1:11 PM
Hi!

I might have overlooked a thread or a post, so feel free to direct me. :)

I've been trying to use private setters for keys and references, but as far as I've figured out it's not possible to have the POCO adapters detect changes on those.
By using the constructor they're loaded fine, but when creating a new entity or updating it, the values/changes are not detected.

Example:
public AggregateRoot
{
public int Id { get; private set; }
public AReference Reference { get; private set; }

public AggregateRoot(int id, AReference reference)
{
this.Id = id; this.Reference = reference;
}

public void SetReference(AReference reference)
{
// validate some state
Reference = reference;
}
}

Having Id as an identity field in the database makes EF select the scope_identity() when inserting and then trying to put it back on the Id property.
I kind of get that it's impossible for the adapter to set that back on the proxy, although it could have done a DetectChange on itself and then create a new proxy using the constructor?

When it comes to the reference though, I don't get why it can't do a DetectChanges on the proxy's property and then set it's own reference property.

Am I just missing something obvious?
Any pointers are appreciated. :)

L-E


Updating...
Page view tracker