Nuts
Nuts

Reputation: 2813

SQLite null value - treat as zero in .NET calculations

What is the most effective way to use null value in SQLite database treated as zero value in .NET calculations? I use Entity Framework.

Let's say I have:

Dim result as Double
result = e_employee_salary * e_index

where e_employee_salary and e_index and fields in the SQLite database but one or both of them can be null and in that case I want to treat them as zero value in the above calculation.

I'm looking the most effective way to do that since these calculations appear in many property getters all over and are called with high frequencies.

Upvotes: 1

Views: 1596

Answers (2)

LS_ᴅᴇᴠ
LS_ᴅᴇᴠ

Reputation: 11161

You may have two approaches: using programming language, as @Claudio or using SQLite query:

 SELECT IFNULL(e_employee_salary, 0.0), IFNULL(e_index, 0.0), ... FROM ...

This way you will always get non-null values from database.

Upvotes: 2

Claudio Redi
Claudio Redi

Reputation: 68410

I could be missing something on your question, but I'd say you could use

If(e_employee_salary, 0) * If(e_index, 0) // VB

(e_employee_salary ?? 0) * (e_index ?? 0) // C#

Upvotes: 0

Related Questions