This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi guys,
In recent nightly builds we're now seeing the following behaviour:
Calling: var customer = uow.Customers.FirstOrDefault(); customer.Country = null; // Where country is a 1-many nullable relationship
Results in: Null Exception
at getfast__customers(Object ) at Mindscape.LightSpeed.Model.FieldModel.<>c__DisplayClass23.<CreateValueGetter>b__9(Object ) at Mindscape.LightSpeed.Model.ToManyModel.GetEntityCollection(Entity ) at Mindscape.LightSpeed.Entity.SetInternal[TField](TField& , TField , String ) at Mindscape.LightSpeed.Entity.Set[TField](TField& field, TField value, String propertyName) at .Model.Customer.set_CompanyId
The error is trying to lookup the new country (null) so it can populate the reverse relationship. If we detach prior to setting to null we can work around it, but this has quite wide ranging impacts.
Thanks,
Mark |
|
|
Hello Mark, I cannot reproduce your error using any combination of eager vs. lazy loading, existing value null or not null, etc. Can you please provide the relevant bits of the Customer and Country entities (just the FK and the association fields will suffice). I also notice that your stack trace doesn't seem to match your code sample. The stack trace shows you setting a FK but you say the issue is when you set the association...? Am I trying the wrong thing? |
|
|
Hi Ivan,
I'm just installing the latest nightly to ensure it's not fixed. Have you tried it with <Guid> (in this case <Guid?>) identities?
Mark |
|
|
Oh and to confirm,
The issue happens when I set a FK. As part of that process Lightspeed attempts to populate the other side of that FK (the reverse association). This is the piece that is failing because the entity doesn't exist (it's null). This might only be happening when the primary entity is being eager loaded.
Will work on a fuller repro for you once I've got the latest code.
Mark |
|
|
I haven't tried it with GUIDs, but it's not something I'd expect to make a difference. If you try it with ints and it does make a difference, let me know and I'll eat Ian's hat my words. |
|
|
Hi Ivan,
I don't have any int entities in my current project - will do a test one up in a little bit.
Some more details: In case below, script has an optional product (1 product to many scripts). Neither side of the relationship is set to eager load.
This fails:
using (var unitOfWork = SqlRepositoryHelper.SqlContext.CreateUnitOfWork()) { var ep = (from e in unitOfWork.Scripts select e).FirstOrDefault(); ep.ProductId = null; }
These work:
using (var unitOfWork = SqlRepositoryHelper.SqlContext.CreateUnitOfWork()) { var ep = (from e in unitOfWork.Scripts //where e.ProductId != null select e).FirstOrDefault(); ep.Product = null; }
using (var unitOfWork = SqlRepositoryHelper.SqlContext.CreateUnitOfWork()) { var ep = (from e in unitOfWork.Scripts select e).FirstOrDefault(); var product = ep.Product; ep.ProductId = null; }
Cheers,
Mark
|
|
|
Thanks for the extra info. I have committed a fix which will be in the next nightly build. |
|
|
We had a hiccup in the overnight build so this isn't up at the moment -- should go up tonight. |
|