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

  • Home
  • SEARCH
  • 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 6197281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:47:37+00:00 2026-05-24T03:47:37+00:00

I have a form view model class that populates Select Lists for use by

  • 0

I have a form view model class that populates Select Lists for use by my views. Below is an extract from a section that creates a SelectList. The problem is that its a lookup table containing 2 other keys

        var waterIndicatorValues = waterIndicator
            .OrderBy(u => u.WaterIndicatorDescription)
            .Select(u => new KeyValuePair<int, string>(u.WaterIndicatorId, u.WaterIndicatorDescription + " [" + u.UnitTypeId.ToString() + "] " + u.HazardTypeId.ToString()));
        this.WaterIndicatorList = new SelectList(waterIndicatorValues, "Key", "Value", water.WaterIndicatorId);

Instead of UnitTypeId and HazardTypeId I want the text descriptions associated with those Id’s. So i’d like my code to look like this :

        var waterIndicatorValues = waterIndicator
            .OrderBy(u => u.WaterIndicatorDescription)
            .Select(u => new KeyValuePair<int, string>(u.WaterIndicatorId, u.WaterIndicatorDescription + " [" + u.UnitTypeId.ToDescription() + "] " + u.HazardTypeId.ToDescription()));
        this.WaterIndicatorList = new SelectList(waterIndicatorValues, "Key", "Value", water.WaterIndicatorId);

This code returns error “Method ‘System.String ToDescription(System.Enum)’ has no supported translation to SQL.”

Any comments/help greatly appreciated

ENUM for UnitTypeId:

using System.ComponentModel;

namespace Emas.Model.Enumerations
{
    /// <summary>
    /// Defines the Unit Types.
    /// </summary>
    public enum UnitType
    {
        [Description("- Please Select -")]
        Blank = 0,

        [Description("kWh")]
        kWh = 1,

        [Description("m3")]
        m3 = 2,

        [Description("litres")]
        litres = 3,

        [Description("Kg")]
        Kg = 4,

        [Description("Unit(s)")]
        Unit = 5,

    }
}
  • 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-24T03:47:38+00:00Added an answer on May 24, 2026 at 3:47 am

    You can’t use extension methods within LINQ that pulls data from the database as it cannot be convert this extension code into SQL. You can however use ToArray() or ToList() to trigger the database hit and then use your extension methods on the result in memory instead.

    Update:

    Based on what you’re trying to achieve in your updated code, I think this article may have the answer you need. You’ll need to cast to the enum type too of course.

    Update 2:

    Converting into memory using ToList() before doing the select with extensions should work ok like below:

        var waterIndicatorValues = waterIndicator
            .OrderBy(u => u.WaterIndicatorDescription)
            .ToList()
            .Select(u => new KeyValuePair<int, string>(u.WaterIndicatorId, u.WaterIndicatorDescription + " [" + u.UnitTypeId.ToDescription() + "] " + u.HazardTypeId.ToDescription()));
        this.WaterIndicatorList = new SelectList(waterIndicatorValues, "Key", "Value", water.WaterIndicatorId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if i have created a view model and have a partial form that is
Well i have a complex form view model like this : public class TransactionFormViewModel
I have a view which queries a model to populate a form: class AddServerForm(forms.Form):
When submitting one form from view, how can i also read or have controller
I have a form class that looks like this: class ApplicationDetailsForm(ModelForm): worked_in_industry = forms.TypedChoiceField(coerce=int,
Hi I have the following view that gets the values for the form fields
I have the following view model: Public Class MyViewModel Public Property SelectedIDs As List(Of
I have a view model public class ViewModel { public string Text { get;
I have form area in my view. If I click button A , I
I have this form in my view: <!-- Bug (extra 'i') right here-----------v -->

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.