Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:28:28+00:00 2026-06-08T18:28:28+00:00

I have 2 very simple queries in entity framework that group by a column

  • 0

I have 2 very simple queries in entity framework that group by a column which is a foreign key. In other words the table fields are:

pk : Primary key
name : name of object
f1: foreign key1
f2: foreign key2
...

I am getting timeout exceptions, in particular this one:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

The queries are:

var q = from x in db.Table select x;
var query_1 = q.GroupBy (record => record.f1);
var query2 = q.GroupBy(record => new {record.f1, record.f2});

I have about 30,000 records in DB and I cannot understand why a simple group by will timeout. Do you have any suggestions of what should I do? Since I am using Entity Framework 4.1, I want to abstract the databse from implementation so I would like a solution that doesn’e change anything in the db engine itself.
Can indexing the f1 or f2 (or both) fields get me a faster query? If so, can someone please explain the concept of indexing as well as how to do is in Enfity Framework?
I don’t think increasing the timeout should be the only solution I should settle on, I am afraid the issue will remain with more data coming.

EDIT:
I have tried what is mentioned here about EF Migrations.

I have this class as result:

namespace DataAccessLayer.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class IX_Table1_fId : DbMigration
    {
        public override void Up()
        {
            Console.WriteLine("Creating Index");
            CreateIndex("Table1", "fId");
            Console.WriteLine("Index Created");
        }

        public override void Down()
        {
            DropIndex("Table1", "IX_Table1_fId");
        }
    }
}

However, when does this code get called? I do not see the print statements I have there in the console.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:28:29+00:00Added an answer on June 8, 2026 at 6:28 pm

    The first thing you have to do is to check where the performance problem is. Start a SQL Server profiler instance, then run the code doing the query. Capture the actual SQL query run and check how long it takes.

    If it is the SQL execution that takes time, the easiest way to analyze it is to paste it into SQL Server Management Studio and run it from there and check the query plan. It will suggest what indexes to add.

    If the query itself is fast, then EFs processing of the result is the problem (which I doubt in this case).

    How you apply the indexes on the database depends on how you handle your database schema. If you hare using EF Migrations to update the schema from the code, then you can add indexes as either a separate migration step or together with the table creation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple table called Member , which consists of the following:
I have a submission table that is very simple: userId, submissionGuid I want to
I have a number of very simple queries that I run for others on
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have a very simple highcharts js chart, which has dates on x-axis and
I have written very very simple console application which supports some command line options.
This is a very simple example: I have a table with two columns, id
I have very simple query. I want to make sure that I don't have
I have a very simple mapping which looks like this (I streamlined the example
I have a very simple item ownership table with these two columns: UserID, ItemID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.