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 have a table that is set for auto number but no records ever get added to this table. 0 has a meaning in our system and it can't be changed. Because this table has a 0 id, when the Entity gets loaded, the Id is set to a negative number. This also causes issues because the collection can't load the object correctly and the record that uses it can't be saved because that column is required. I tried cheating and changing the type to KeyTable but the id just gets changed from the negative number to the NextId in the table, which changes every time. Without changing the data in the database, is there away around this? Joe |
|
|
Unfortunately there is no easy solution for this. I think we may be able to make a fix that allows loaded entities (as opposed to new entities) to have ID 0 -- the reason the problem occurs is that we register the entity in the UOW before we mark it as being in the default state, and being in the new state means that the 0 gets interpreted by the registration code as "I need an ID" rather than "I have ID 0", so we may be able to fix this just by changing the order -- but I am not sure what the impact on the rest of the system would be so this would require significant testing.One rather horrible possibility is to create a view for this particular entity. The view would just duplicate the ID column into another column. You would map the entity to the view using TableAttribute, and create a field, but no property, for this extra column. Then you would override GeneratedId() to return the value of the extra field. I have not tested this and I am not sure what the impact would be (and it would probably not work if you ever needed to save the entity back to the DB), but it may be worth having a quick go to see if it looks promising as a workaround. |
|
|
I am going to remove the association for now and just not use LS to load that entity set up. I will just use the raw values at that point. I need to search all of the old code to see why this 0 was even there to begin with instead of using a nullable field. My guess is the access application was not using a left join and this was the fix. This table is at least 10 years old and I don't think anyone has inserted a new record in the past 5. It does seem that a table that says it has a primary key, should have a restriction on what that value may be for loaded objects. It is actually more interesting on how LS tries to save a record that uses that field. I tried to just set the Id field instead of the Entity and it still did not save. I will see if I can find a workaround for now. Thanks, Joe |
|
|
Changing the field to nullable allowed me to save the record (LS did not validate the field). So the only issue now is the 0 when loading. I will just use a dataset for that entity for now until we can figure out a workaround. Thanks, Joe |
|
|
http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=2066
|
|