Ambiguous method call when comparing FieldEntity to null

Posts   
 
    
stoneyowl avatar
stoneyowl
User
Posts: 62
Joined: 29-Jan-2004
# Posted on: 06-Jan-2006 16:10:07   

Ran into an interesting error. When using the following code:


EntityField fld = (EntityField)Courses.Fields[colname];
if (fld != null)   <<< compile time error here!!
{
 .... do things
}

I get the following error on the marked line...

The call is ambiguous between the following methods or properties: 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField.operator !=(SD.LLBLGen.Pro.ORMSupportClasses.EntityField, System.Collections.ArrayList)' and 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField.operator !=(SD.LLBLGen.Pro.ORMSupportClasses.EntityField, SD.LLBLGen.Pro.ORMSupportClasses.Expression)'

There are situations where the name passed in will not have a matching data field in the Courses entity. Since, without the null EntityField check, I get an exception complaining that the variable 'fld' is null, I thought the null check would work.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Jan-2006 16:20:22   

compare with DBNull.Value :) flushed nooo, you don't need that. My mistake. I thought you were building a predicate. Indeed, casting to the interface solves it, see Walaa's answer simple_smile .

Frans Bouma | Lead developer LLBLGen Pro
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-Jan-2006 16:28:13   

Or if you are checking for the existance of such field you may use the following instead:

IEntityFieldCore fld = (EntityField)Courses.Fields[colname];
if (fld != null) <<< compile time error here!!
{
.... do things
}
stoneyowl avatar
stoneyowl
User
Posts: 62
Joined: 29-Jan-2004
# Posted on: 06-Jan-2006 17:03:42   

Yep, that fixed it. Thanks!