DbContext timeout while running linq query
<p>I have the following async method that queries for some data on a database.</p>

<pre><code>private async Task&lt;List&lt;MyObject&gt;&gt; GetTotalConcert(DateTime d1, DateTime d2, string[] name)
        {
            using (RegistrationDbContext context = new RegistrationDbContext())
            {
                IQueryable&lt;MyObject&gt; results;

                results = (from t1 in context.Table1
                           join t2 in context.Table2 on t1.Id equals t2.Id
                           where (t2.CreatedOn &gt;= d1 &amp;&amp; t2.CreatedOn &lt; d2)
                           &amp;&amp; (name.Contains(t2.Name))
                           &amp;&amp; t1.EventName.Equals("Concert")
                           select new MyObject
                           {
                               Id = t2.Id,
                               EventName = t1.EventName,
                               Status = t2.Status,
                               ProjectName = t2.Name
                           });

                return await results.Distinct().ToAsyncEnumerable().ToList();
            }
        }
</code></pre>

<p>This code, fails with a timeout exception in cases where the date range is too wide. I tried to increase the timeout by doing this:</p>

<pre><code>public class RegistrationDbContext : DbContext
    {
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            base.Database.SetCommandTimeout(300);

        }
        // Some more code here....
    }
</code></pre>

<p>Is there anything that I am doing wrong here? If I run the SQL query on the database itself, it takes close to 18 seconds for the same date range...</p>

<p>I am using ASP.NET 5 MVC6 and EF7.</p>

<p>How can I get rid of the timeout exception for these cases where the time range is too wide and takes more time for the db to return the data?</p>