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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:21:31+00:00 2026-06-08T16:21:31+00:00

I have an INT fields called TradeNo that may contain NULL value. The requirement

  • 0

I have an INT fields called TradeNo that may contain NULL value. The requirement is to display on the dropdown the “contract Id” and the “trade no” in bracket and if “trade no” is null, then display N/A.

Example:
44444 (2222)
55555 ( N/A )

Here’s what I thought would work. This is my functions that returns a SelectList

public IEnumerable<SelectListItem> GetContractsBySupplierDropDown(string supplier)
{
    var result = from c in context.Contracts 
                     where c.Supplier==supplier 
                     orderby c.ContractID
                     select new { 
                            Text = c.ContractID.ToString() + " (" + 
                                   (c.TradeNo.HasValue  ? 
                                       c.TradeNo.Value.ToString() : 
                                       " N/A ").ToString() + 
                                    " )", 
                            Value = c.ContractID };

    return new SelectList(result, "Text", "Value"); 
}

The error being return is:

LINQ to Entities does not recognize the method 'System.String ToString()'
method, and this method cannot be translated into a store expression.

From what I can tell, the error displayed means that EF is trying to convert ToString to a database function?

  • 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-08T16:21:35+00:00Added an answer on June 8, 2026 at 4:21 pm

    Unfortunately you cannot use ToString in a number field coming from the database.

    As a work around you can cast ToList before doing it, so then the contents are in the memory.

    public IEnumerable<SelectListItem> GetContractsBySupplierDropDown(string supplier)
    {
        var query =  from c in context.Contracts 
                     where c.Supplier==supplier 
                     orderby c.ContractID
                     select new {
                         c.ContractID,
                         c.TradeNo,
    
                     };
        var result = from c in query.ToList()
                     select new { 
                                Text = c.ContractID.ToString() + " (" + 
                                       (c.TradeNo.HasValue  ?
                                           c.TradeNo.Value.ToString() : 
                                           " N/A ") + 
                                        " )", 
                                Value = c.ContractID
                      };
    
        return new SelectList(result, "Text", "Value");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have filled List<Object1> Object 1 contain 2 fields (int id & string name)
I have a table called Inventory with the fields Item (varchar), Amount (int), Type
I have a table called Follow , with three fields: Id (autoincrement int), UserId
I have a simple mysql table called messages with the following fields: ID(int) MESSAGE(varchar)
I have an object called Person that has the following properties: int id; Name
I have a persistent class Author with two fields: int id , String name
I have a table in db2 which has the following fields int xyz; string
I have this table (TableA): ( [FieldA] [int] NOT NULL, [FieldB] [int] NOT NULL,
I have a database table called Genre with the following fields: Id (Seeded Primary
I have a defined a content type called SPVideoDataItem containing those two fields: <Field

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.