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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:31:42+00:00 2026-05-15T19:31:42+00:00

I have an Expression that converts one type of object to another type. The

  • 0

I have an Expression that converts one type of object to another type. The expression is as follows:

public Expression<Func<SQLRepository.ActionType, Model.ActionType>> DBActionTypeToActionType =
(SQLRepository.ActionType at) => new Model.ActionType()
{
    ID = at.OID,
    DisplayName = at.DisplayName
};

I can use the Expression like this:

var linq = (from at in dc.SQLRepositoryDC.ActionTypes select at).Select(DBActionTypeToActionType);

But I’d like to use it like this:

var linq = (from at in dc.SQLRepositoryDC.ActionTypes select DBActionTypeToActionType.Compile().Invoke(at));

I’ve been looking for a couple days now and I can only find references to doing this in the Where clause. It seems that if I’m able to use the function calls to do this, it should be possible using the query syntax.

The reason it is important to do use the query syntax is that some of the objects that are being selected are composed of many sub-objects and trying to chain them all of the conversions together with the function notation will be much harder to write and maintain.

  • 1 1 Answer
  • 1 View
  • 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-15T19:31:43+00:00Added an answer on May 15, 2026 at 7:31 pm

    It seems that if I’m able to use the function calls to do this, it should be possible using the query syntax.

    That’s not true. Query notation always goes via a lambda expression. For example

    from x in y select z
    

    ends up as

    y.Select(x => z)
    

    That means if you’ve already got an expression tree that you want to pass directly as the argument to Select, you can’t use query expressions because there’s this extra level of indirection.

    Now the options available depend on where you need to apply the predefined expression. You can always use it in the source, and then continue with the query:

    var query = from foo in dc.ActionTypes.Select(DBActionTypeToActionType)
                where foo.Stuff
                select foo.Other;
    

    Or using it at the end is easy:

    var query = (from bar in dc.ActionTypes
                 where bar.Stuff
                 select bar).Select(DBActionTypeToActionType);
    

    Does that help at all?

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

Sidebar

Related Questions

I have a piece of code that converts an infix expression to an expression
I have a regex expression that I'm doing a split against another string and
I have this Regular Expression that matches the following strings: <!-- 09-02-2009 ---> <!--
I have a Python regular expression that contains a group which can occur zero
I have a Python regular expression that matches a set of filenames. How to
I have the following regular expression that works fine in perl: Classification:\s([^\n]+?)(?:\sRange:\s([^\n]+?))*(?:\sStructural Integrity:\s([^\n]+))*\n The
I have the following LINQ expression that's not returning the appropriate response var query
Does anyone have a regular expression handy that will match any legal DNS hostname
Over the years I have slowly developed a regular expression that validates most email
I have a regular expression ^[a-zA-Z+#-.0-9]{1,5}$ which validates that the word contains alpha-numeric characters

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.