title: Nested filter on Data Transfer Object using OData Wep Api
body: <p>I have a wep api project consumes data using odata but I'm having some problems with odata wep api.</p>
  
  <p>when I execute that query</p>
  
  <blockquote>
    <p>/api/values?$top=50&amp;$filter=Comments/Fortuneteller/FullName eq 'some string'</p>
  </blockquote>
  
  <p>it gives me following error</p>
  
  <blockquote>
    <p>"Message": "The query specified in the URI is not valid.",
    "ExceptionMessage": "The parent value for a property access of a property 'Fortuneteller' is not a single value. Property access can only be applied to a single value."</p>
  </blockquote>
  
  <p>I don't want to return entity object from controller. Is there any way to filter the entity via DTO?</p>
  
  <p>I'm using Repository + Service layer pattern in my project and structure of my project is like that</p>
  
  <blockquote>
    <p>api controller &lt;-> service &lt;-> repository &lt;-> EF</p>
  </blockquote>
  
  <p><strong>api controller</strong></p>
  
  <pre><code>    [Queryable]
      public IQueryable&lt;FortuneDTO&gt; Get()
      {
          return service.FiterBy((_ =&gt; true));
      }
  </code></pre>
  
  <p><strong>service</strong></p>
  
  <pre><code>    public IQueryable&lt;FortuneDTO&gt; FiterBy(Expression&lt;Func&lt;tblFortune, bool&gt;&gt; filter)
      {
          return repository.List().Where(filter).Select(_ =&gt; new FortuneDTO
          {
              CreatedByFullName = _.aspnet_Users.FullName,
              Id = _.FortuneId,
              Comments = _.tblComment.Select(c =&gt; new CommentDTO
              {
                  Id=c.CommentId,
                  Comment = c.Comment,
                  Fortuneteller = new FortunetellerDTO { 
                      FullName=c.aspnet_Users.FullName,
                      Id=c.aspnet_Users.UserId
                  }
              }).AsQueryable()
          });
      }
  </code></pre>
  
  <p><strong>repository</strong></p>
  
  <pre><code>    public virtual IQueryable&lt;TEntity&gt; List()
      {
          return context.CreateObjectSet&lt;TEntity&gt;();
      }
  </code></pre>
  
  <p><strong>DTO's</strong></p>
  
  <pre><code>public class FortuneDTO
  {
      public int Id { get; set; }
      public string CreatedByFullName { get; set; }
      public IQueryable&lt;CommentDTO&gt; Comments { get; set; }
  }
  public class CommentDTO
  {
      public int Id { get; set; }
      public string Comment { get; set; }
      public FortunetellerDTO Fortuneteller { get; set; }
  }
  public class FortunetellerDTO
  {
      public Guid Id { get; set; }
      public string FullName { get; set; }
  }
  </code></pre>