linq, asp.net

Attached codes are working fine. Just I am just afraid if i.RepNumber (from DB) is empty, then above codes will break.
In this codes base, is it a way to do like

if i.RepNumber is not null then
do convert.int(i.RepNumber) >= 700

Because I don't think compare operator in string is not really working in logic.
item.txt
LVL 1
ITsolutionWizardAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
That's why I included the check for null   ; )
0
 
käµfm³d 👽Commented:
Change your where clause:

where i.RepNumber != null && i.RepNumber >= 700 && !ids.Contains(p.SUBMTDNMBR)

Open in new window

0
 
Fernando SotoRetiredCommented:
Not the way you have it in the query and by the way it is missing a select clause.

If the value has a null for i.RepNumber do you want it in the result?
If yes what value do you want in its place?
What is the data type of i.RepNumber?

Please post the complete query. Thanks
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ITsolutionWizardAuthor Commented:
i.RepNumber is string. do nothing if it is null.
0
 
Fernando SotoRetiredCommented:
Well then in the select clause you can do something like this.

RepNumber = i.RepNumber ?? "",
0
 
käµfm³d 👽Commented:
@Fernando Soto

Does ?? get turned into a COALESCE by EF/L2S?

@ITsolutionWizard

My new suggestion would then be:

where i.RepNumber != null && Convert.ToInt32(i.RepNumber) >= 700 && !ids.Contains(p.SUBMTDNMBR)

Open in new window

0
 
Fernando SotoRetiredCommented:
@Kaufmed, They get translated differently in EF and L2S

In EF they build a CASE in the select something like
CASE WHEN ([Extent1].[RepNumber] IS NULL) THEN N'' ELSE [Extent1].[RepNumber] END AS [C1]

In L2S they use the T-SQL COALESCE
SELECT [t0].[Column1], COALESCE([t0].[RepNumber],@p0) AS [RepNumber]
0
 
ITsolutionWizardAuthor Commented:
Convert.ToInt32(i.RepNumber) >= 700 wil break if db.column has nothing
0
 
ITsolutionWizardAuthor Commented:
It is still break with that
0
 
Fernando SotoRetiredCommented:
Can you post the current code that you are using.
0
 
ITsolutionWizardAuthor Commented:
That is the heart of the codes. I can't post you everything here. It is too complex and hard to understand.
within that linq query. I just hope to do If it is null, then not to run something.

int.parse(d.repnumber) looks like is not very practical to me because if the data from null, it will be broken.
0
 
Fernando SotoRetiredCommented:
I would like to see how you have implemented what was suggested to make sure that what was suggested has not been misunderstood and implemented in a way we did not intend.
0
All Courses

From novice to tech pro — start learning today.