Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use reflection</p> <pre><code>x.GetType( ).GetProperty("MyProperty").GetValue( x, null ); </code></pre> <p>although this might work, i wouldn't advise on doing this, why don't pass in your where clause as an expression like:</p> <pre><code>myMethod&lt;T&gt;(Expression&lt;Func&lt;T,bool&gt;&gt; where) </code></pre> <h2>example after comment:</h2> <p>consider the following type:</p> <p>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</p> <pre><code>public class MyTypeOfXService { private DataDataContext Context; public MyTypeOfXService() { Context = new DataDataContext("example code"); } public IQueryable&lt;MyTypeOfX&gt; GetTypeOfX(Expression&lt;Func&lt;MyTypeOfX, bool&gt;&gt; where) { return this.Context.MyTypeOfXes.Where(where); } } </code></pre> <p>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:</p> <pre><code>class Program { static void Main(string[] args) { var service = new MyTypeOfXService(); var queryById = service.GetTypeOfX((mytype) =&gt; mytype.Id == 1); var queryByName = service.GetTypeOfX((mytype) =&gt; mytype.Name == "MyName"); var queryByName = service.GetTypeOfX((mytype) =&gt; mytype.Name == "MyName" &amp;&amp; mytype.Id == 1); } } </code></pre> <p>as you can see, we can build a where clause on any property or combination of properties.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload