Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> Setting a field to NULL
 

Pages: 1
Bugs & Issues
Setting a field to NULL
Page:1/1 

  Print all messages in this thread  
Poster Message
Rosacek
User



Location:
CZ
Joined on:
18-Mar-2012 18:02:44
Posted:
133 posts
# Posted on: 09-Feb-2013 14:35:29.  
Hi,
I couldn't save null to MSSQL to nullable columns of date by LLBL Pro Runtime v.3.5.12.703, adapter.

Code:

Dim lEntityToUpdate As New EntityClasses.OrderBookPoEntity(zaznam.OrderbookPoid) With {
.IsNew=False
.Comment = "something new", _
.CommentVendor = "ok", _
.RequestedDate = Nothing}

adapter.SaveEntity(lEntityToUpdate)


Above code updated any field to the new value except RequestedDate
Then I found http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=19894
Based on that I moved down the command .IsNew=False right before SaveEntity.

Updated code
Code:

Dim lEntityToUpdate As New EntityClasses.OrderBookPoEntity(zaznam.OrderbookPoid) With {
.Comment = "something new", _
.CommentVendor = "ok", _
.RequestedDate = Nothing}

lEntityToUpdate.IsNew = False
adapter.SaveEntity(lEntityToUpdate)


This code successfully updates also RequestedDate to NULL.

Question 1:
Why does it depend when IsNew=False is set? I guess it should not matter if IsNew=False is called as first command or last command right before SaveEntity

Question 2:
Why does it depend when IsNew=False is set just for fields set to Nothing? Other fields changed to any value are updated correctly, even .IsNew is the first line before any entity field change.

I feel this is strange behaviour of LLBL Pro

In your doc is an example how to "ADAPTER/Using the entity classes, Adapter/Update an entity directly in the persistent storage"
And .IsNew is also very first line in your example code, see:
Code:

' [VB.NET]
Dim customer As New CustomerEntity()
customer.CustomerID = "CHOPS"
customer.IsNew = False
customer.Phone = "(605)555-4321"
Using adapter As New DataAccessAdapter()
    adapter.SaveEntity(customer)
End Using

  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8086 posts
# Posted on: 11-Feb-2013 06:00:16.  
Hi Rosacek,

The problem isn't .IsNew. Setting .IsNew to false allows you to emit an Update even where the entity wasn't fetched.

The problem is that when you instantiate the entity, RequestedDate field is NULL, then you set to NULL again, that won't flag the field as 'Changed'. Only 'Changed' fields are included in the UPDATE list.

To workaround this, you can mark the as Changed:
Code:
...
// this in C#, you should convert it to VB
lEntityToUpdate.Fields["RequestedDate"].IsChanged = true;
adapter.SaveEntity(lEntityToUpdate);



David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Rosacek
User



Location:
CZ
Joined on:
18-Mar-2012 18:02:44
Posted:
133 posts
# Posted on: 12-May-2014 21:19:52.  
It might be good idea to update example in DOC
Option 2: Update an entity directly in the persistent storage
http://www.llblgen.com/documentation/4.1/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/gencode_usingentityclasses_adapter.htm#Modifyinganentity

and move down the statement customer.IsNew = False to be the last one right before Using adapter ...
With some note, that entity.IsNew = False should be the last entity setting, because if you want to update some fields to NULL, then IsNew=False should be bellow that. Therefor the best position of .IsNew=False is the last line before save.

Code:
' [VB.NET]
Dim customer As New CustomerEntity()
customer.CustomerID = "CHOPS"
customer.Phone = "(605)555-4321"
customer.Fax=Nothing
customer.IsNew = False
Using adapter As New DataAccessAdapter()
    adapter.SaveEntity(customer)
End Using

  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8086 posts
# Posted on: 13-May-2014 07:49:36.  
Also setting .IsChanged to true does the trick. Manipulating .IsNew is not the official way of doing things, so we don't promote that workaround, but still, it's usable sometimes. We will look forward into your documentation observation. Thanks for the feedback.

David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37631 posts
# Posted on: 13-May-2014 10:35:57.  
Updated. Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.