Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Excluded fields and NULL
 

Pages: 1
LLBLGen Pro Runtime Framework
Excluded fields and NULL
Page:1/1 

  Print all messages in this thread  
Poster Message
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 29-Dec-2016 15:37:04.  
Say you have fetched an entity without one of its nullable fields, and later you update that field conditionally. For example:

Code:

var coll = new EntityCollection<PersonEntity>();
adapter.FetchEntityCollection(coll, ... new ExcludedFieldList(PersonFields.Photo));
...
foreach (var e in coll)
{
     e.Name = "Joe";
     ...
     if (some condition)
     {
         object photo = GetPhoto();
         e.SetNewFieldValue((int)PersonFieldIndex.Photo, photo);
     }
}
adapter.SaveEntityCollection(coll);


We noticed that if photo==NULL, then the field is not updated. Otherwise it does. Is that by design? It seems inconsistent, and forces us to either fetch all the fields (which is redundant), or rewrite the code to update the entities directly (which is more convoluted).

  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37870 posts
# Posted on: 30-Dec-2016 11:07:08.  
I think this is a side effect of the feature, sadly. The field is excluded and for the entity its value is 'null'. When you set it to null explicitly, the value actually doesn't change (null stays null) and the field isn't marked as changed.

There are a couple of ways around this, the easiest is this:

instead of:
Code:
e.SetNewFieldValue((int)PersonFieldIndex.Photo, photo);


do:
Code:
e.Fields.SetCurrentValue((int)PersonFieldIndex.Photo, photo);


This will always set the changed flag and should make the field 'dirty', causing it to be picked up. It also bypasses checks whether the value is the same, so it will always set it to a new value in the DB issuing an update query.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 30-Dec-2016 16:09:24.  
Thanks for the tip!
And happy new year..
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37870 posts
# Posted on: 30-Dec-2016 16:14:16.  
obzekt wrote:
Thanks for the tip!
And happy new year..

You too! 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.