Can't update binary field

Posts   
 
    
Valdar
User
Posts: 24
Joined: 07-Oct-2005
# Posted on: 19-Dec-2005 19:36:12   

I am having trouble with binary fields and had to develop a hack to work around it. It's been working, but I'd like to find a proper way to update binary fields.

I have a field called SecurityMask for my CustomerEntity. SecurityMask is a binary 20 field. Here is the code that we use that works:

byte[] bySecurityMask = oCustomer.SecurityMask; oCustomer.SecurityMask = new byte[]{0}; ... //some code that changes bySecurityMask ... oCustomer.SecurityMask = bySecurityMask; adapter.SaveEntity(oCustomer);

Here is the code that doesn't work:

byte[] bySecurityMask = oCustomer.SecurityMask; ... //some code that changes bySecurityMask //Technically it's just changing oCustomer.SecurityMask since //it's a pointer, but we like to seperate out our variables. ... oCustomer.SecurityMask = bySecurityMask; adapter.SaveEntity(oCustomer);

For some reason, we have to set our binary fields to a new array, then set the value we want before the change is accepted.

This is for all binary fields on all entity, not just for this particular Entity.

Anyone know what is going on here? Is it because the pointer value is not updating that SecurityMask is not updating when saving? That's the best that I could figure out.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-Dec-2005 20:30:37   

What's the runtime libray version you're using? Please state the build version. (rightmouse on ormsupportclasses dll -> properties -> version tab in explorer)

Frans Bouma | Lead developer LLBLGen Pro
Valdar
User
Posts: 24
Joined: 07-Oct-2005
# Posted on: 19-Dec-2005 21:51:06   

Version: 1.0.20051.51203

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-Dec-2005 22:18:10   

Valdar wrote:

Version: 1.0.20051.51203

Thanks. I'll setup a repro case and see what's causing this.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-Dec-2005 12:21:29   

OK, this is what I tried:


CompanyPropertyEntity toAlter = (CompanyPropertyEntity)fetchedCompany.CompanyProperty[0];
byte[] fkValue = toAlter.CompanyId;
fkValue[0]=64;
fkValue[1]=64;

Assert.IsTrue(toAlter.IsDirty);
Assert.IsTrue(toAlter.Fields[(int)CompanyPropertyFieldIndex.CompanyId].IsChanged);

CompanyId is a byte[16] value.

Now, the two asserts fail, as you also encounter. Though the values are the same, fkValue is the same instance as the value of toAlter.CompanyId and toAlter.CompanyId has the same value as fkValue after the edit.

This is caused by the fact that you may change the values INSIDE the array, but the field doesn't know that, as the byte array doesn't signal that its internal values have changed. So you can alter the values inside the array, but the field will not see those changes and will stay 'unchanged'.

At the moment where you set it again to a value, it gets updated because it sees that the value has been updated. There was an issue in the runtime libs fixed after your version, which checks per array value if a value is the same (fixed on 13-dec-2005, see: http://www.llblgen.com/pages/secure/ChangeLogBrowser.aspx ) and which is an update you should use in your situation, as you deal with byte arrays. If you don't use byte arrays (binary/varbinary) fields for PK's (and thus FK's) it's not a required update in your situation.

Frans Bouma | Lead developer LLBLGen Pro
Valdar
User
Posts: 24
Joined: 07-Oct-2005
# Posted on: 20-Dec-2005 23:44:13   

Thanks! I'll get that new version.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Dec-2005 08:09:55   

Valdar wrote:

Thanks! I'll get that new version.

Just to be clear: that doesn't 'fix' this issue you reported, because that's unfixable. It solves another problem you might run into simple_smile .

Frans Bouma | Lead developer LLBLGen Pro