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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:14:25+00:00 2026-05-31T11:14:25+00:00

In my app I have to display some information about customers (a customer has

  • 0

In my app I have to display some information about customers (a customer has a code and a name). One of the fields is ‘display name’, where

DisplayName = Code + " - " + Name

I retrieve the customer from database into a view model and set the DisplayName, like this:

from   customer in this.Context.Customers
select new CustomerViewModel
       {
           DisplayName = customer.Code + " - " + customer.Name
       }

But I would like to extract this logic into an expression or function because I use it in multiple places and if the logic changes (for example DisplayName = Name), then I have to do a lot of changes.

Therefore, I have created this function

Func<Customer, string> CustomerDisplayName = (c => c.Code + " - " + c.Name)

and use it this way:

from   customer in this.Context.Customers
select new CustomerViewModel
       {
           DisplayName = CustomerDisplayName(customer)
       }

It works fine and makes the logic reusable, but the problem is that the function cannot be parsed into an SQL statement, so LinqToSql first retrieves the data (‘Code’ and Name’) and then executes the function for each record.

Should I be worried about performance (if I have a lot of data), and stick with the first option ? Or is it ok to use the 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-05-31T11:14:27+00:00Added an answer on May 31, 2026 at 11:14 am

    In your model you have the class Customer, which is a partial class (see the file yourDataClasses.designer.cs).

    So, you only must to modify the file yourDataClases.cs, adding the partial class Customer and adding it the property DisplayName.

    Your code in yourDataClases.cs looks like:

    public partial class Customer
    {
       public int DisplayName
       {
          get
          {
             return this.Code + " - " + this.Name;
          }
       }
    }
    

    Your queries would be well:

    var res = from c in this.Context.Customers select c;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET web app (C#) where I get some information from a
I have written a piece of code, to get some information through the website
I have to make an iphone app for some customer. He should be able
I`m building simple app which shows information about most car brands. I have rootViewController
My app design required a page that display 'user information' and i currently have
My app have a background image that fills the screen. I'd like to display
I have create web app in MVS 3 but failed to display alert message
I have a view controller based app that contains several views that I display/hide
I have a UIWebView in my app which I want to use to display
I have an asp.net mvc 2 app. I need to display the same page

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.