Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, while it may not be a true abstraction any longer, the main point was to get the benefit of linq to sql without updating all the queries already written.</p> <p>so, I made the IRepository implement IQueryable instead of IEnumerable.</p> <p>then in the SqlClientRepository implementation, I can call AsQueryable() to cast the Table to IQueryable, and then all is good, like so.</p> <p>Now everywhere somebody has written IRepository().Where(qi => qi.id = id) or similar, it actually passes the ID to sql server and only pulls back one record, instead of all of them, and loops through looking for the correct one.</p> <pre><code>/// &lt;summary&gt;Provides the ability to query and access entities within a SQL Server data store.&lt;/summary&gt; /// &lt;typeparam name="T"&gt;The type of entity in the repository.&lt;/typeparam&gt; public sealed class SqlClientRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class { private readonly Table&lt;T&gt; _source; private readonly IQueryable&lt;T&gt; _sourceQuery; IQueryable&lt;T&gt; Query() { return (IQueryable&lt;T&gt;)_source; } public Type ElementType { get { return _sourceQuery.GetType(); } } public Expression Expression { get { return _sourceQuery.Expression; } } public IQueryProvider Provider { get { return _sourceQuery.Provider; } } /// &lt;summary&gt;Initializes a new instance of the &lt;see cref="SqlClientRepository{T}"/&gt; class.&lt;/summary&gt; /// &lt;param name="source"&gt;A &lt;see cref="Table{T}"/&gt; to a collection representing the entities from a SQL Server data store.&lt;/param&gt; /// &lt;exception cref="ArgumentNullException"&gt;&lt;paramref name="source"/&gt; is a &lt;c&gt;null&lt;/c&gt; reference (&lt;c&gt;Nothing&lt;/c&gt; in Visual Basic).&lt;/exception&gt; internal SqlClientRepository(Table&lt;T&gt; source) { if( source == null ) throw new ArgumentNullException( "source", "All_TableIsNull" ) ); _source = source; _sourceQuery = _source.AsQueryable(); } </code></pre>
    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.
 

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