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 8998719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:04:26+00:00 2026-06-16T00:04:26+00:00

In sql server I create views where I can check for null values and

  • 0

In sql server I create views where I can check for null values and replace them with a default if I want (i.e. ISNULL(PrimaryPhone, ‘No Primary #’) AS PrimaryPhone. I used a lot of views in my asp.net web forms application, but I am now learning MVC 4 and want to start out right.

I have a model, controller and view set up for my client table. I would like to be able to replace null/empty values with (“Not Entered”) or something like that.
I believe this needs to go in the controller, please correct me if I’m wrong.

I saw an example that uses hasvalue, but it is not available through intellisense.

How would I replace empty/null values without using DefaultValue in my model?

Thanks

var result = db.Clients.Select(x => new
        {
            CustomerID = x.CustomerID,
            UserID = x.UserID,
            FullName = x.FullName,
            EmailAdd = x.emailadd.DefaultIfEmpty("No Email"),....
  • 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-16T00:04:27+00:00Added an answer on June 16, 2026 at 12:04 am

    You can use the ?? operator to set a default value when something is null:

    var result = db.Clients.Select(x => new
            {
                CustomerID = x.CustomerID,
                UserID = x.UserID,
                FullName = x.FullName,
                EmailAdd = x.emailadd ?? "No Email", ...
    

    If you need more control, for example checking for both null and empty, you can also use the ?: operator (also known as the “conditional operator” or “ternary operator”):

    var result = db.Clients.Select(x => new
            {
                CustomerID = x.CustomerID,
                UserID = x.UserID,
                FullName = x.FullName,
                EmailAdd = string.IsNullOrEmpty(x.emailadd) ? "No Email" : x.emailadd, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql server table: CREATE TABLE [Workflow].[MilestoneDate]( [MilestoneDateId] [int] IDENTITY(1,1) NOT NULL,
I've got a (SQL Server 2005) database where I'd like to create views on-the-fly.
It's possible to create digrams in SQL Server 2000 that can be useful to
SQL Server Mgmt Studio is driving me crazy. If I create a view and
In my SQL Server 2005 server I create databases and logins using Management Studio.
When I perform a select/Insert query, does SQL Server automatically create an implicit transaction
I'm using VB.NET and Microsoft SQL Server 2005 to create an application. I was
I know how to create a job dynamically from this create-sql-server-job-automatically The issue I
I am trying to create an add-in by using the article below http://blogs.microsoft.co.il/blogs/shair/archive/2008/07/28/how-to-create-sql-server-management-studio-addin.aspx I
SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT,

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.