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
|
I was attempting to call a entity.MyThoughAssociation.AddRange(entity2.MyThoughAssociation); and I got an object reference not equal to an instance of an object error |
|
|
Could you provide a stack trace please? Were both ThroughAssociation properties initialised (non-null) at the point of the call? Thanks! |
|
|
System.NullReferenceException: Object reference not set to an instance of an object. Also here is the code for AddRange public static void AddRange<T>(this IList<T> list, IEnumerable<T> items) |
|
|
Funny I run this twice. The first time it works on enity1 the second time it does not on entity2. Then I run it first on entity2 and it works then on entity 1 in fails
|
|
|
It looks like one of the associations is not being initialised before being used (its internal EntityCollection of the through entities is null). Could you check that both collections are loaded, e.g. by doing a Debug.WriteLine(e.MyThroughAssociation.Count) for each entity before the AddRange call? If that still gives the NullReferenceException then check the MyThroughAssociation property getter and ensure that you do a Get() for the through collection before initialising the _myThroughAssociation backing field. |
|
|
"MyThroughAssociation property getter and ensure that you do a Get() for the through collection before initialising the _myThroughAssociation backing field." My code is Lightspeed Generated |
|
|
Sorry, I've had a go at reproducing this and it seems to be working okay for me. Can you provide a small project and data set that reproduces the problem? Thanks! |
|
|
I changed my code as follows ..... int c = ShipperItems.Count; ........ public static void AddRange<T>(this IList<T> list, IEnumerable<T> items)
in Debugging the AddRange Function items shows two members and their Ids loopItems shows two members the first one null and the second not. It is very odd that on of the Items returned from a ToList() is null. |
|
|
Yes, that is strange (assuming ShipperItems is the ThroughAssociation). It sounds like there might be something in the data that causing LightSpeed to get confused. Are you using soft delete? Could one of the through entries be referencing a soft-deleted object? |
|
|
I turned SoftDelete off of the ShipperItem class and that seemed to work. But now when I save I get this error PartDef is invalid It seems like it is trying to save things out of order. I made sure all Items that change have a Shipper, ShipperItem, Part and PartDef.
|
|
|
I found a work around that creates the parts before the shipperitems are created and that solves the problem. Though it is very odd behavior. Lucky that this is a fairly new feature and not many shipper items have been create so far. |
|