Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:04+00:00 2026-06-18T03:50:04+00:00

I have an MVP app that reads data from a SQL DB using EntityFramework.

  • 0

I have an MVP app that reads data from a SQL DB using EntityFramework. That data is copied from an external CMS website database, so the data isn’t always reliable.

One of the fields I read is of ‘bit’ datatype in SQL, and is either a 1 or 0, and ASP.NET MVC wants it as a boolean, otherwise I get errors about converting boolean to int.

The problem is sometimes that bit value can be NULL in the DB, and that crashes my MVC app. I can’t check for NULL, because I get errors that the boolean datatype can only be true or false.

Example

Model

namespace Foo.Models
{
    [Table("provider")]
    public class Bar
    {
        //can't check for null here, getter and setter only allow boolean
        public Boolean FooBar { get; set; }
    }
}

Controller

namespace Foo.Controllers
{
    public ActionResult BarList()
    {
         //Can't check for null here, because if(Boolean == null) will always evaluate to false
         List<Bar> bars = db.Bar.ToList();
         return View(bars);
    }
}

If FooBar is ever NULL, an error is thrown in the view that I can’t have a NULL in a boolean. How do I handle this situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:50:05+00:00Added an answer on June 18, 2026 at 3:50 am

    You can use a generic Nullable<bool> (can also be expressed as bool?):

    Nullable<bool> nullableBool;
    

    Then use it as follows:

    bool realBool = (nullableBool.HasValue && nullableBool);
    
    // or
    
    if (nullableBool == true) { ... } // true
    else { ... } // false or null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gwt-project that is comunication to database. Application design mvp pattern and view
Have been learning about MVP and have tried writing a test app using it
Using a MVP Pattern in a WinForms app I have been asked to write.
I have a GWT App and I am using GWT MVP with Places /
I have a GWT 2.4 app using MVP, clientFactory, activities, places, and uiBinder. I
We're developing a .NET 3.5 Windows Forms app, using LINQ to SQL and MVP.
I have made a website with php/mysql that is using the mvc architecture. I
I am learning GWT and i have read at multiple places that using MVP
I have been playing around with the MVP pattern using winforms for the last
I have seen numerous questions on MVP that mostly revolve around the View and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.