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
|
Hey guys, I'm getting a bit of a strange error while trying to add optimistic locking to my classes. I have the following class structure.
public class BaseEntity : Entity<Guid>
All other entities extend BaseEntities.
I then create 2 entities, a Spider, and a UserPlan. Both have EntityState = new. Whenever I perform a set like the following. TestUserPlan test = TestUserPlanFactory.Create(); spider.UserPlan = test;
I always receive the following stack track.
System.NullReferenceException: Object reference not set to an instance of an object.
at Mindscape.LightSpeed.EntityHolder`1.Mindscape.LightSpeed.IEntityHolder.get_FieldName() in EntityHolder.cs: line 117
at Mindscape.LightSpeed.Entity.SetInternal(IEntityHolder entityHolder, Entity value) in Entity.cs: line 948 at Mindscape.LightSpeed.Entity.Set<TEntity>(EntityHolder`1 entityHolder, TEntity value) in Entity.cs: line 932 at WebModel.Model.Spider.set_UserPlan(SpiderPlan value) in Spider.cs: line 688 at UnitTests.Model.Plans.Spiders.AirwaysPlanTests.SetUserPlan(Spider spider) in AirwaysPlanTests.cs: line 40 at UnitTests.Model.Plans.Spiders.AirwaysPlanTests.InvalidSpiderCreatedDate() in AirwaysPlanTests.cs: line 67 I'm not sure why I'm getting this, these tests worked well before optimistic locking. I've tried stepping through the LS source, and for some reason the AssociationModel isntance is null. Any ideas what's going on?
thanks,
Todd
|
|
|
Just to be clear, neither of my objects are null. They also both have CreatedOn and UpdatedOn dates of '1/1/0001 12:00:00 AM' and lockVersion of 0. |
|
|
No idea what would cause that, and I've had a go at reproducing it but it works fine for me. Can you verify that it still occurs in the most recent nightly, and assuming it does could you provide us with a small complete project (e.g. a NUnit test) that reproduces the problem? Thanks! |
|
|
Hi Ivan, No dice with the latest nightly. Note that the SpiderPlan class itself is abstract, so it has multiple subclasses. Can you try that with your example and see if it breaks the persist?
Thanks, Todd |
|
|
Nope, I tried introducing a STI hierarchy including an abstract base class and it's still working for me.
|
|
|
Hi Ivan, I've tried to create a simple test case and I can't reproduce it either. Given that we've slowly upgraded since version 1, I'm assuming there may be something hanging around that may not need to be there. Is there someplace I could upload my test suite to you? Given that it's sensitive IP, I don't want to post it on the form.
|
|
|
I've found the issue. These tests subclass our Spider entity with a test class "TestSpider". This subclass allows us to mock up/modify the CreatedOn date that is used to test some of our process logic.
It seems LS blows up when I use subclasses for my test. I'm not quite sure why I'm getting this behavior, I never actually add or save the Entities in any unit of work. I only need to construct the object graph in memory then run it through. Any ideas how I can get around mocking up the createdOn date if subclassing will not work?
Thanks Todd |
|