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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
ITsolutionWizardAuthor Commented:
i.RepNumber is string. do nothing if it is null.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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
käµfm³d 👽Commented:
That's why I included the check for null   ; )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.