Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have long complicated entities then creating a projection by hand is a nightmare. <code>Automapper</code> doesn't work because LINQ cannot use it in conjunction with IQueryable.</p> <p>This here is the perfect solution : <a href="http://www.devtrends.co.uk/blog/stop-using-automapper-in-your-data-access-code" rel="nofollow"><code>Stop using AutoMapper in your Data Access Code</code></a></p> <p>It will generate a projection 'magically' for you and enable you to run an oData query based on your DTO (data transfer object) class.</p> <pre><code> [Queryable] public IQueryable&lt;DatabaseProductDTO&gt; GetDatabaseProductDTO(ODataQueryOptions&lt;DatabaseProductDTO&gt; options) { // _db.DatabaseProducts is an EF table // DatabaseProductDTO is my DTO object var projectedDTOs = _db.DatabaseProducts.Project().To&lt;DatabaseProductDTO&gt;(); var settings = new ODataQuerySettings(); var results = (IQueryable&lt;DatabaseProductDTO&gt;) options.ApplyTo(projectedDTOs, settings); return results.ToArray().AsQueryable(); } </code></pre> <p>I run this with </p> <pre><code>/odata/DatabaseProductDTO?$filter=FreeShipping eq true </code></pre> <p>Note: this article is from a couple years ago and it's possible that by now <code>AutoMapper</code> has functionality like this built in. I just don't have time I check this myself right now. The inspiration for the above referenced article was based on <a href="http://lostechies.com/jimmybogard/2011/02/09/autoprojecting-linq-queries/" rel="nofollow">this article</a> by the author of AutoMapper itself - so it's possible some improved version of it is now included. The general concept seems great and this version is working well for me.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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