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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:50:25+00:00 2026-05-11T19:50:25+00:00

Get value out of DateTime column if null to return String.Empty else DateTime.ToShortDateString What

  • 0

Get value out of DateTime column
if null to return String.Empty
else
DateTime.ToShortDateString

What am I doing wrong => query produced below:

var queryable = from p in Products
    select new {
               selldate = p.SellEndDate == null
                           ? string.Empty
                           : p.SellEndDate.Value.ToShortDateString()  };

Error: InvalidOperationException: Could not translate expression ‘Table(Product).Select(p => new <>f__AnonymousType01(selldate = IIF((p.SellEndDate = null), Invoke(value(System.Func1[System.String])), p.SellEndDate.Value.ToShortDateString())))’ into SQL and could not treat it as a local expression.

  • 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-05-11T19:50:25+00:00Added an answer on May 11, 2026 at 7:50 pm

    Basically what’s happening here is that LINQ to SQL is taking your entire query and trying to convert it into something that SQL Server can understand. The problem, though, is that SQL Server has no concept of DateTime.ToShortDateString, so the conversion to SQL fails.

    You’ll have to change your query so that it just selects SellEndDate (which will get it as a Nullable<DateTime>) and then when you use the results of that query you can do the conversion to string. For example:

    var list = (from p in Products
               select p.SellEndDate).ToList();
    
    // calling ToList() above means we have the entire resultset in memory and
    // no longer have to pass the query back to SQL Server
    
    var stuff = from p in list select new
    { 
        selldate = p.SellEndDate == null ?
                       string.Empty :
                       p.SellEndDate.Value.ToShortDateString()
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 111k
  • Answers 111k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Turns out the tables I kept choosing to test, the… May 11, 2026 at 9:45 pm
  • Editorial Team
    Editorial Team added an answer The options (or preferences) button in the Firefox add-ons window… May 11, 2026 at 9:45 pm
  • Editorial Team
    Editorial Team added an answer Thanks for the suggestions guys. I figured it out. The… May 11, 2026 at 9:45 pm

Related Questions

I need to store user entered changes to a particular table, but not show
I recently built a query in SQL that I can use to look at
.NET 3.5, C# I have a web app with a search feature. Some of
I'm calling the following code: protected void SetCookieValue( string sCookieName, object oValue, DateTime dtExpires)
I want to use the DateTime.TryParse method to get the datetime value of a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.