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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:32:59+00:00 2026-05-28T23:32:59+00:00

Problem I use linq to return a list of anonymous objects from s in

  • 0

Problem

I use linq to return a list of anonymous objects

from s in _subsidiaryService.Repository.Query()
   where  s.Title.ToLower().Contains(term) ||
   s.Description.ToLower().Contains(term) ||
   s.District.ToLower().Contains(term)
   select new
              {
                  label = s.Title
                  ,
                  desc = s.Description
                  ,
                  value = s.ID
                  ,
                  icon = Url.Content(Path.Combine(string.Format(Constants.RelativePathSubsidiary, s.ID), SmallIconFileName))  //Problem line!!
              }

The line icon is where the problem is

Linq to Entities does not recognize Path.Combine or string.Format

Questions

I have two questions:

  1. How can I run and Path.Combine string.format inside my queries
  2. How do I create functions that run inside my queries? e.g:

Code sample

from s in _subsidiaryService.Repository.Query()
   where  s.Title.ToLower().Contains(term) ||
   s.Description.ToLower().Contains(term) ||
   s.District.ToLower().Contains(term)
   select new
              {
                  label = s.Title
                  ,
                  desc = s.Description
                  ,
                  value = s.ID
                  ,
                  icon = getIconPath(s.SmallIconFileName)
              }

My method

public string getIconPath(Guid id, sring fileName) {
    return Url.Content(Path.Combine(string.Format(Constants.RelativePathSubsidiary, id), fileName));
}
  • 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-28T23:33:00+00:00Added an answer on May 28, 2026 at 11:33 pm

    Change it to:

    (from s in _subsidiaryService.Repository.Query()
    where  s.Title.ToLower().Contains(term) ||
    s.Description.ToLower().Contains(term) ||
    s.District.ToLower().Contains(term)
    select s).AsEnumerable().Select(s => new { label = s.Title, desc = s.Description, value = s.ID, icon = getIconPath(s.SmallIconFileName) });
    

    The .AsEnumerable() switches it from the query to in memory operations, so it doesn’t try to map the functions to the database.

    Its worth noting though that this means it runs everything up to the .AsEnumerable on the database, pulls it locally to an IEnumerable then starts iterating it to do the anonymous object creation. So there are performance implications to doing this. It may be worthwhile to trim the columns you are selecting by using an anonymous object or making sure all of your Where filtering is done prior to the AsEnumerable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I return a List from a Linq query, and after it I have to
I've just started to use linq to sql and have run into a problem
Come across a problem with the repository pattern combined with the use of abstract
I'm having a problem passing an list of application-defined objects to RIA services. I
While trying to use LINQ to SQL I encountered several problems. I have table
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
The Problem I use a tool at work that lets me do queries and
The problem: We use a program written by our biggest customer to receive orders,
I have found a problem with use JQuery timeout, i have a page with
Okay, so here's my problem: We use FOP for creating pretty report output. We

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.