GetFieldByName crashes on NULL data

Posts   
 
    
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 16-Feb-2010 22:24:55   

Llblgen 2.6 Final Released 7/3/2009 sqlserver 2005 dotnet 3.5

2 of my colleagues have told me that <entity>.GetFieldByName(<stringfieldname>) throws exception when the data value of the field is NULL. Obviously the database says the column is nullable and llblgen entity does declare the field as nullable.

Does any one run into this problem? Is this a bug or is it intentional feature?

Right now we just wrap a try-catch block around the statement xxx.GetFieldByName(yyy) and handle the exception.

Thank you

BZ

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Feb-2010 23:36:53   

Having had a look at the code, GetFieldByName does not appear to go anywhere near the field values, it simply returns an EntityField corresponding to the supplied name, or null if the field is not found.

Could your colleagues by trying to do <entity>.GetFieldByName<fieldname>.somemethod, but in some way getting the field name wrong - this would throw a nullreference exception.

When you say 2 colleagues have told you this, have you tried it for yourself ? The source code for the ORMSupportClasses is in the SDK, which is in the download section of the website, once you have logged in with your customer ID and password.

This would allow you to debug into the code to see exactly what is happening.

Matt

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 17-Feb-2010 10:02:56   

Sorry. What I meant was GetFieldValue. No I have not ran the code that crashed but since both of my colleagues told me so I gave them the benefit of the doubt and think that it is true.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 17-Feb-2010 11:00:43   

Sorry. What I meant was GetFieldValue

Sorry, I can't find this method anywhere.

Could you please provide a code snippet.

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 17-Feb-2010 23:18:28   

Sorry guys. I should have taken a look at the code before I trusted my colleagues and posted for help. First of all there's no GetFieldValue. Second, The exception is thrown because they not only get the field by name but they also get the current value of the field AND invoke ToString function of a null object!

fieldValue = trySave.GetFieldByName("EmployerNo").CurrentValue.ToString();
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Feb-2010 05:14:54   

bunzee wrote:

Sorry guys. I should have taken a look at the code before I trusted my colleagues and posted for help. First of all there's no GetFieldValue. Second, The exception is thrown because they not only get the field by name but they also get the current value of the field AND invoke ToString function of a null object!

fieldValue = trySave.GetFieldByName("EmployerNo").CurrentValue.ToString();

Hehe, Ok, no worries smile

David Elizondo | LLBLGen Support Team