Setting Entity.Property to Null

Posts   
 
    
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 06-Apr-2007 00:02:35   

Sorry for all the questions today. stuck_out_tongue_winking_eye

If I have an entity fetched from the database with a nullable field whose value is null, and I reset the value of the field to null again, should this cause the field and entity to be marked changed (and thus generate an update)?

So (pseudocode):



ProductEntity product = new ProductEntity();
product.property = null;

Save(product);
product2 = FetchProduct(product.Id);

product2.property = null;
Save(product2);


I would think there would be no update statement generated, since I'm not actually changing anything. However, an update statement is getting emitted, and I wanted to know if this is expected behavior.

Thanks,

Phil

(Edit: I have also tried setting the property using SetNewFieldValue--same result). (Edit #2: Version 2.0 with latest runtimes, adapter vs. SQL 2005).

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 06-Apr-2007 00:45:22   

psandler wrote:

Sorry for all the questions today. stuck_out_tongue_winking_eye

If I have an entity fetched from the database with a nullable field whose value is null, and I reset the value of the field to null again, should this cause the field and entity to be marked changed (and thus generate an update)?

So (pseudocode):



ProductEntity product = new ProductEntity();
product.property = null;

Save(product);
product2 = FetchProduct(product.Id);

product2.property = null;
Save(product2);


I would think there would be no update statement generated, since I'm not actually changing anything. However, an update statement is getting emitted, and I wanted to know if this is expected behavior.

Thanks,

Phil

(Edit: I have also tried setting the property using SetNewFieldValue--same result). (Edit #2: Version 2.0 with latest runtimes, adapter vs. SQL 2005).

I know you can directly set the .CurrentValue of the EntityField object to Null/Nothing, but I don't know if this is the recommended way.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Apr-2007 12:02:43   

Which runtime library version do you use? Because I think this issue was solved in the v2.0.07.0317 build of the runtime library.

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 06-Apr-2007 15:36:37   

Walaa wrote:

Which runtime library version do you use? Because I think this issue was solved in the v2.0.07.0317 build of the runtime library.

Arg, I didn't copy the new versions down to the /lib folder.

Thanks Walaa!