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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:37:07+00:00 2026-05-14T23:37:07+00:00

I have code something like this in an IRepository implementation in Linq to Sql:

  • 0

I have code something like this in an IRepository implementation in Linq to Sql:

var newlist = from h in list where h.StringProp1 == "1"
                      select new MyBusinessBO{
                          firstProp = h.StringProp1,
                          secondProp = h.StringProp2
                      };

The projection into MyBusinessBO is not difificult but when the Business Object has many properties the projection code becomes very lengthy. Also, as the projection can occur in several places in the Repository we break the DRY principle.

Is there any way to abstract out the projection or replace it with a delegate?

I.e. replace the code

                          firstProp = h.StringProp1,
                          secondProp = h.StringProp2

with something reusable?

  • 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-14T23:37:08+00:00Added an answer on May 14, 2026 at 11:37 pm

    Queryable.Select requires an Expression<Func<T, U>>. You can write a method that returns this and use that method everywhere you do the transformation.

    public Expression<Func<DataObj, BusiObj>> GetExpr()
    {
      return h => new BusiObj()
      {
        firstProp = h.StringProp1,
        secondProp = h.StringProp2
      };
    }
    
    
     //get a local variable holding the expression.
    Expression<Func<DataObj, BusiObj>> toBusiObj = GetExpr();
    
    //use it thusly
    var newList = (from h in list where h.StringProp1 == "1" select h)
      .Select(toBusiObj)
      .ToList();
    
    //or
    List<BusiObj> newList = list
      .Where(h => h.StringProp1 == "1")
      .Select(toBusiObj)
      .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • 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 Relevant: How to check if an embedded SVG document is… May 17, 2026 at 1:54 am
  • Editorial Team
    Editorial Team added an answer You have several problem here. First, tables are no designed… May 17, 2026 at 1:53 am
  • Editorial Team
    Editorial Team added an answer If we have a look at all middlewares loaded in… May 17, 2026 at 1:53 am

Trending Tags

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

Top Members

Related Questions

I have a repository pattern setup using NHibernate. The base class looks like this:
I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
I have the understanding that using data access routines directly from presentation code is
I have this PHP class, whose purpose is to fetch some configuration data from
I have a bunch of Repository classes which all look a bit like the
I recently started using Mercurial and like the way I have VCS protection for
I wanted to avoid the switch statement. I have over 30 document types. There
I am in the process of refactoring our BI layers to make our code
I have multimedia files and its metadata stored in a RDBMS (actually, the actual
I have parent child relationship between two entities(Parent and Child). My Parent mapping is

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.