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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:44:18+00:00 2026-05-24T16:44:18+00:00

How can I do something like this: var result = db.MyTable.Where(x => x.MyProperty ==

  • 0

How can I do something like this:

var result = db.MyTable.Where(x => x."MyProperty" == "Test" );

As you can see I want to access “MyProperty” but give the property name as a sting.

  • 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-24T16:44:20+00:00Added an answer on May 24, 2026 at 4:44 pm

    You could use reflection

    x.GetType( ).GetProperty("MyProperty").GetValue( x, null ); 
    

    although this might work, i wouldn’t advise on doing this, why don’t pass in your where clause as an expression like:

    myMethod<T>(Expression<Func<T,bool>> where)
    

    example after comment:

    consider the following type:

    you see there are three properties where the name is of type string and id is of type int. now if we wrap our database context in a service like this

    public class MyTypeOfXService
    {
        private DataDataContext Context;
        public MyTypeOfXService()
        {
            Context = new DataDataContext("example code");
        }
    
        public IQueryable<MyTypeOfX> GetTypeOfX(Expression<Func<MyTypeOfX, bool>> where)
        {
            return this.Context.MyTypeOfXes.Where(where);
        }
    }
    

    in our get method there is an Expression parameter that takes two generics, the first is our type x and the second is a boolean. The advantage of this approach is that we can abstract all the data context creation and only express an where clause in our code see final piece of code:

    class Program
    {
        static void Main(string[] args)
        {
            var service = new MyTypeOfXService();
    
            var queryById = service.GetTypeOfX((mytype) => mytype.Id == 1);
            var queryByName = service.GetTypeOfX((mytype) => mytype.Name == "MyName");
            var queryByName = service.GetTypeOfX((mytype) => mytype.Name == "MyName" && mytype.Id == 1);
        }
    }
    

    as you can see, we can build a where clause on any property or combination of properties.

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

Sidebar

Related Questions

If I write something like this: var img = $(new Image()).attr('src', image.src); How can
How can I dynamically name id's using javascript? Something like this: js: var idName
I mean can I do something like this: var client = new WebClient(); var
How can I group by multiple columns using linq projection? Something like this: var
I want to do something like this: var w = window.open(javascript: makeAnAjaxRequest();); My question
I can do something like this: validator.showErrors({ nameOfField : ErrorMessage }); And that works
I know you can do something like this: readlines(FileName) -> {ok, Device} = file:open(FileName,
How I can do something like this in C++: void my_print(format_string) { vector<string> data;
does anyone know if you can do something like this using the (N)Hibernate criteria
In postgres I am fairly sure you can do something like this SELECT authors.stage_name,

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.