I have a table with a “t_cftc_ir_swaps
” with following fields
T_CFTC_IR_SWAP_ID Integer (Autonumber, PK)
PRODUCT Varchar
TRADEVOLUME_TYPE Varchar
TRADEVOLUME_BUCKET_1 Varchar
TRADEVOLUME_BUCKET_2 Varchar
TRADEVOLUME_GROUP Varchar
TRADEVOLUME Integer
RELEASE_DATE Date
TRADE_DATE Date
I am using Entity Framework at the code level. I am trying to insert a record into this table. But before doing that I am checking if the record already exists in the table. For that purpose I have a “RecordAlreadyExists” function code as follows
Now in some of the records in the data table we have null values for “TRADEVOLUME_BUCKET_2” but while inserting a new record if I try to compare the record being added (with a null value for TRADEVOLUME_BUCKET_2) against the underlying table records it returns “0” records even though I can query the database and see there are matching records in the table.
At the code break this is the record I am trying to insert. As you can see it has null value for “TRADEVOLUME_BUCKET_2”
The count of records matching with the records which we are trying to add is “0”
When I run a query at the database level I do get a matching record already in the underlying table
I have even tries using DBNull at code as follows
But get the following exception when I try to do that at runtime “Unable to create a null constant value of type ‘System.Object’. Only entity types, enumeration types or primitive types are supported in this context”
How should I compare null values using LINQ query?