DbValue not serialized over WCF, causing a problem to set a nullable field value to null

Posts   
 
    
AmitayD
User
Posts: 45
Joined: 22-Aug-2007
# Posted on: 27-Dec-2007 20:16:59   

Using: LLBLGen Pro 2.5 final September 24th 2007 Oracle 10g via ODP.Net Adapter templates for .Net 2.0 (general) On .Net Framework 3.5

Hi! I think i have a genuine bug here... simple_smile When transferring an entity over WCF, Its fields DbValue(s) are set to null. This is causing me serious issues when trying to update a nullable field to null, since the DetermineIfFieldShouldBeSet() in UtiltyClasses, using the DbValue to determine if a change is required.

I've managed to reproduce it with a simple application: We have an LLBLGen project with one enity for one table: TestNullable: ID (number(5)) - PK NullableNumber (number(5)) - Nullable

I'v put one record there with values (2, 2)

There's a wcf service in one web site application that simply fetches the entity by ID and returns it, and a console client application that uses the wcf. The Enity class is known to both sides, i.e. the WCF client proxy does not create any proxy class for it.

Then we can see that the DB Value is null, though the actual value is 2. Setting the nullable value to null will do nothing (SetValue returns false).

here's the client code that demonstrates the problem:


            //We'll get the entity through WCF, so after serialization
            ServiceReference1.ServiceClient client = new TestConsole.ServiceReference1.ServiceClient();
            TestNullableEntity transferredEntity =  client.GetEntity(1);

            Console.Write("transferredEntity.NullableNumber Value:");
            Console.WriteLine(transferredEntity.NullableNumber);
            //Print 2 - correct value
            Console.Write("transferredEntity.Fields[\"NullableNumber\".DbValue:");
            //Prints Null - should be 2
            Console.WriteLine(transferredEntity.Fields["NullableNumber"].DbValue);

            //Update the value to null:
            transferredEntity.NullableNumber = null;
            //Still Prints 2 - value was not set
            Console.Write("transferredEntity.NullableNumber Value after setting to null:");
            Console.WriteLine(transferredEntity.NullableNumber);

            //Update the value to -99:
            transferredEntity.NullableNumber = -99;
            //Still Prints 2 - value was not set
            Console.Write("transferredEntity.NullableNumber Value after setting to -99:");
            Console.WriteLine(transferredEntity.NullableNumber);

            //Update the value to null again
            transferredEntity.NullableNumber = null;
            //now prints null - value was set
            Console.Write("transferredEntity.NullableNumber Value after setting to null:");
            Console.WriteLine(transferredEntity.NullableNumber);


            Console.Read();
            return;

I've attached to reproduction code. I had to delete some DLLs from the bins, so you have to link them to local version. The projects and solution are Visual studio 2008 ones. It might be a fixed bug, but haven't seen it in the change log.

If you have any further questions i'll be able to reply only on sunday... Thanks and have a good weekend, Amitay Dobo

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Dec-2007 10:11:06   

The DBValue with other properties/data that's not sent over the wire to reduce the size of the sent message. Try using the folloiwng to set the field's value to null.

transferredEntity.Fields["NullableNumber"].ForcedCurrentValueWrite(null);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 28-Dec-2007 11:24:37   

Update to the latest runtime library build, this was fixed some time ago.

Frans Bouma | Lead developer LLBLGen Pro
AmitayD
User
Posts: 45
Joined: 22-Aug-2007
# Posted on: 30-Dec-2007 11:06:13   

Thanks, I can confirm the the fix solves that issue! Sorry i didn't check it with the latest version. For the record i did search the changelog for any relevant fixes, but found only about serializing a string field with a null value. Amitay

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 30-Dec-2007 12:08:55   

I believe it was discovered with this issue:

Compact25 Xml serialization/deserialization (Adapter): string typed entity fields which had a value of "" in the database, got their DbValue set to null/Nothing after deserialization. Bug is still present in Compact/Verbose formats, though fix can't be done at this point due to breaking changes for CurrentValue, which gets its value set to "" when the value is null/Nothing and the field type is string. The fix for Compact / Verbose is postponed till v2.6. WCF/Webservice XML serialization uses Compact25.

November 12th.

Frans Bouma | Lead developer LLBLGen Pro