Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> TypeDefaultValue not being returned
 

Pages: 1
Bugs & Issues
TypeDefaultValue not being returned
Page:1/1 

  Print all messages in this thread  
Poster Message
Steve
User



Location:
CT
Joined on:
20-Dec-2004 21:02:00
Posted:
24 posts
# Posted on: 17-Jun-2008 04:36:53.  
After executing the following:

entEmail.Subject = "this seems to be a new issue with LLBLGen 2.5"
entEmail.Subject = null,


entEmail.Subject still has the value of "this seems to be a new issue with LLBLGen 2.5"

TypeDefaultValue is not being called (breakpoint is not being hit).

The Subject field is a varchar(50) and does not allow Nulls.

project properties:
ConvertNulledReferenceTypesToDefaultValue = True
GenerateNullalbeFieldsAsNullableTypes = True

(however, this second setting shouldn't matter since the Subject field does not allow Nulls in the db anyway)

It's like the ConvertNulledReferenceTypesToDefaultValue flag being ignored or something.

Any suggestions?


config:
LLBLGen Pro 2.5 with SQL Svr 2005 (have the same issue with LLBLGen Pro 2.6)
SelfServicing
target platform .NET 3.5
using the 2.0 runtimes

Thanks !
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8076 posts
# Posted on: 17-Jun-2008 05:30:09.  
Hi Steve, as the field isn't nullable, a null assignment is not allowed, isn't?

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



Location:
CT
Joined on:
20-Dec-2004 21:02:00
Posted:
24 posts
# Posted on: 17-Jun-2008 18:03:13.  
Thanks for the quick reply.
You're right, null will not be allowed back into the db. But at runtime, I do need the value to be able to be set to null in memory, or at least be set to empty string from typedefaultvalue. Either would be ok. I was expecting null to be disallowed and typedefaultvalue to return string.empty.

Is this behavior intended, or am I missing something?

SetNewFieldValue() also produces same result.
  Top
goose
User



Location:
Central America
Joined on:
06-Aug-2007 18:21:05
Posted:
385 posts
# Posted on: 17-Jun-2008 20:38:48.  
Try using System.DBNull instead. You could as well follow the practical approach to this issue, just setting the value to String.Empty would do the work.

gansodesoya  Top
Steve
User



Location:
CT
Joined on:
20-Dec-2004 21:02:00
Posted:
24 posts
# Posted on: 17-Jun-2008 21:38:56.  
strings can't be set to DBNull.Value, ether directly or with SetNewFieldValue()

What is causing the value to be set to null is databinding in a .NET DataGridView, so it's not something that's happening programatically.

I need some way to allow

    myEnt.Subject = null

to not be ignored.

LLBLGen didn't used to do this. Is this an intentional change in behavior?
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37546 posts
# Posted on: 17-Jun-2008 23:04:18.  
Steve wrote:
strings can't be set to DBNull.Value, ether directly or with SetNewFieldValue()

What is causing the value to be set to null is databinding in a .NET DataGridView, so it's not something that's happening programatically.

I need some way to allow

    myEnt.Subject = null

to not be ignored.

LLBLGen didn't used to do this. Is this an intentional change in behavior?

What exactly do you mean 'didn't used to do this' ? Which version did allow you to set a non-nullable field to null?

Anyway, TypeDefaultValue is used when a value is retrieved from the field (this is a change in v2.5). Before the field was set to the default value, this isn't the case for some time already (since 2.5 at least, I've to look it up but it might be already since 2.0).

How exactly is the field set to null through databinding? You empty a cell and it is then passing null instead of an empty string to the field, which then fails? So you want to pre-process the value set to the field?


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



Location:
CT
Joined on:
20-Dec-2004 21:02:00
Posted:
24 posts
# Posted on: 17-Jun-2008 23:48:51.  
I went back to an app using v2.0 to doublecheck. I was wrong about previous behavior. A property would only make use of TypeDefaultValue when attempting to set it to null if the field itself allowed nulls in the database.

To answer your databinding question, yes, apparently the .NET DataGridView passes null to the datasource property when the user simply clears the text from a cell. We previously used the ComponentOne grid, so we never ran into this problem.

So as it is now, when user attempts to clear the text from a cell and then leaves the cell, the prior value reappears. Dissapointed

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14495 posts
# Posted on: 18-Jun-2008 12:13:19.  
Would you please attach a simple repro solution?
(Better to be based on northwind)

Thanks.


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37546 posts
# Posted on: 18-Jun-2008 20:31:16.  
I think it also can be done with a CellFormatting event handler (which handles that event from the DataGridView), and in there, the value is checked, if it's null, it's changed to String.Empty.

Another solution might be an override of PreProcessValueToSet in a partial class of the entity. (see reference manual for details, is virtual method in EntityBase/EntityBase2 )

In there you can convert null to empty string if you want to, it then is set properly
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Steve
User



Location:
CT
Joined on:
20-Dec-2004 21:02:00
Posted:
24 posts
# Posted on: 18-Jun-2008 21:21:33.  
I like the CellFormatting idea. I'll give it a shot.

Thanks for the ideas and quick responses.


  Top
Steve
User



Location:
CT
Joined on:
20-Dec-2004 21:02:00
Posted:
24 posts
# Posted on: 19-Jun-2008 19:51:49.  
Unfortunately the CellFormatting event fires after the grid passes null to the bound entity collection.

The solution to this problem is actually to make use of the DefaultCellStyle.DataSourceNullValue property of the DatGridView columns (which isn't visible in the CellStyleBuilder in the designer):


foreach (DataGridViewColumn col in grid1.Columns)
col.DefaultCellStyle.DataSourceNullValue = myLLBLGenProj.HelperClasses.TypeDefaultValue.GetDefaultValue(col.ValueType);


Thanks again for the suggestions. Your product is great.
  Top
Pages: 1  


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

Version: 2.1.12172008 Final.