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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:27:55+00:00 2026-05-31T04:27:55+00:00

I have viewmodel (say memberviewmodel) and ef model (say member). how do i translate

  • 0

I have viewmodel (say memberviewmodel) and ef model (say member). how do i translate from

> GetByProperty(Expression<Func<MemberViewModel, bool>> whereCondition)

to

> GetByProperty(Expression<Func<Member, bool>> whereCondition)

any ideas?

My service exposes the method GetByProperty(Expression> whereCondition) but then within the service, it calls the business object which exposes a method GetByProperty(Expression> whereCondition).

  • 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-31T04:27:56+00:00Added an answer on May 31, 2026 at 4:27 am

    To convert Expression<Func<MemberViewModel, bool>> to Expression<Func<Member, bool>> you’ll need to extend the ExpressionVisitor class. I’ve assumed MemberViewModel contains only fields and properties. Member of course needs to implement the same set of fields and properties. In this case the following should work:

    public class ParameterModifier<TSrc, TDest> : ExpressionVisitor
    {
        ParameterExpression parameter;
    
        public ParameterModifier()
        {
            parameter = Expression.Parameter(typeof(TDest), "member");
        }
    
        protected override Expression VisitParameter(ParameterExpression node)
        {
            if (node.Type == typeof(TSrc))
            {
                return parameter;
            }
            else
                return base.VisitParameter(node);
        }
    
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.Expression.Type == typeof(TSrc))
            {
                return Expression.PropertyOrField(Visit(node.Expression), node.Member.Name);
            }
            else
            {
                return base.VisitMember(node);
            }
        }
    
        protected override Expression VisitLambda<T>(Expression<T> node)
        {
            if (node.Parameters.Any(p => p.Type == typeof(TSrc)))
            {
                return Expression.Lambda(Visit(node.Body), node.Parameters.Select(p => p.Type == typeof(TSrc) ? parameter : p));
            }
            else
            {
                return base.VisitLambda<T>(node);
            }
        }
    }
    

    Before passing the predicate to the second method you can now convert it using the class above:

    IEnumerable<MemberViewModel> GetByProperty(Expression<Func<MemberViewModel, bool>> whereCondition)
    {
        var converter = new ParameterModifier<MemberViewModel, Member>();
        var convertedExpression = converter.Visit(original) as Expression<Func<Member, bool>>;
        IEnumerable<Member> members = GetByProperty(convertedExpression);
        return members.Select(new MemberViewModel(member));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say I have a view where I currently only use Model information from
I have a user control let say UC1 . This user control have viewmodel
Let's say I have the following selectlist (Countries) in a ViewModel: //.. private static
In my application, I have a model object that contains a collection lets say
I have a ViewModel class which has large number of properties(Say 50). Once the
Lets say I have a viewmodel like this var viewModel = { Dtos: [{
Let's just say I have A ViewModel that is made up of 3 other
I have a User Control, let's say TextboxPage and it's associated with ViewModel, TextboxPageViewModel.
Lets say I have a LineItem (from the over used Shopping Cart example) and
Let's say in some abstract ViewModel base-class I have a plain-old property as follows:

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.