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, I am using Lightspeed 4 against a legacy database that uses Identity Columns for Ids. I have a DistributionList entity that has a many-to-many relationship with User entities. I have established a through association from DistributionList to User to give me a User collection on the DistributionList entity. In the User table, there is a record with an Id of 0 (zero) which must have been added manually (as I said, legacy database), hence it falls outside the start/increment parameters for the Identity Column. If I have a DistributionList with this particular User in its Users collection, then when I try to do something like distributionList.Users.ToList(), I get a null object in the collection position where this zero Id User should be. Looking at the SQL that Lightspeed emits to hydrate the collection, it never requests the User record with the Id of 0. I assume this is a feature of Lightspeed, i.e. it assumes all Identity Column values are greater than zero. Is there some workaround I can implement to overcome this problem? Thanks |
|
|
While not specific to using the IdentityColumn method, I am assuming your 1-to-many association between the through entity and the user will be marked as non nullable (e.g. UserId will be set to an int rather than an int?). LightSpeed uses the default value for the field to determine if that field has a value, so if it is non nullable then the default value of 0 is used to handle this, so that means you are getting null returned for the associated User entity. You can check this by loading the specific through entity which refers to the User and you will see that indeed it appears as null there as well. To work around this mark the association as nullable (even if that cant actually happen in the database) and that will allow entities with an id of 0 to be loaded as they will not longer be the default value.
Jeremy |
|