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

  • Home
  • SEARCH
  • 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 4025322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:49:56+00:00 2026-05-20T10:49:56+00:00

Okay, I know I have to be doing something wrong here because the performance

  • 0

Okay, I know I have to be doing something wrong here because the performance times I’m getting are so different its shocking. I’ve been considering using the code first option of entity in an existing project of mine so I’ve been trying to do some performance test just to see how it compares. I’m using MSpec to run the tests against a remote development database.

Here are my tests:

public class query_a_database_for_a_network_entry_with_linq : ipmanagement_object {
    protected static NetINFO.IPM_NetworkMaster result;
Because of = () => {
    var db = new NetINFODataContext();
    result = db.IPM_NetworkMasters.SingleOrDefault(c => c.NetworkID == 170553);
};

It should_return_an_ipm_networkmaster_object = () => {
    result.ShouldBeOfType(typeof(NetINFO.IPM_NetworkMaster));
};

It should_return_a_net_ou_object_with_a_networkid_of_4663 = () => {
    result.IPM_OUIDMaps.First().NET_OU.NET_OUID.ShouldEqual(4663);
};   

}

public class query_a_database_for_a_network_entry_with_entity_code_first : ipmanagement_object {
    protected static NetInfo.Core.Models.CTP.IPM_NetworkMaster result;

    Because of = () => {
        NetInfo.Core.Models.CTP.NetInfoDb db = new NetInfo.Core.Models.CTP.NetInfoDb();
        result = db.IPM_NetworkMasters.SingleOrDefault(c => c.NetworkID == 170553);
    };

    It should_return_an_ipm_networkmaster_object = () => {
        result.ShouldBeOfType(typeof(NetInfo.Core.Models.CTP.IPM_NetworkMaster));
    };

    It should_return_a_net_ou_object_with_a_networkid_of_4663 = () => {
        result.NET_OUs.First().NET_OUID.ShouldEqual(4663);
    };
}

As you can see from the datacontext with linq-to-sql I can’t access object directly that have a many to many relationship. I have to use the intermediate lookup table. Which is one of the things I like about Entity framework. However when I run these test the linq test never takes longer than 4 seconds to complete (database is remote). Where the entity test takes almost 8 seconds every time. Not for sure why there is such a huge difference?? Here is excerpts of my POCO classes and my dbcontext:

DbContext:

public class NetInfoDb : DbContext {
        public NetInfoDb() : base("NetINFOConnectionString") { }
        public DbSet<IPM_NetworkMaster> IPM_NetworkMasters { get; set; }
        public DbSet<IPM_NetworkType> IPM_NetworkTypes { get; set; }
        public DbSet<NET_OU> NET_OUs { get; set; }

        protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder) {
            modelBuilder.Entity<IPM_NetworkMaster>()
                  .HasMany(a => a.NET_OUs)
                  .WithMany(b => b.IPM_NetworkMasters)
                  .Map(m => {
                      m.MapRightKey(a => a.NET_OUID, "NET_OUID");
                      m.MapLeftKey(b => b.NetworkID, "NetworkID");
                      m.ToTable("IPM_OUIDMap");
                  });
        }

    }

IPM_NetworkMaster:

public class IPM_NetworkMaster {
        public int NetworkID { get; set; }
        <snip>            
        public virtual ICollection<NET_OU> NET_OUs { get; set; }

    }

NET_OU:

public class NET_OU {
        public int NET_OUID { get; set; }
        <snip>
        public virtual ICollection<IPM_NetworkMaster> IPM_NetworkMasters { get; set; }
    }
  • 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-05-20T10:49:57+00:00Added an answer on May 20, 2026 at 10:49 am

    As everyone has mentioned, you need to profile your queries. Assuming you are using SQL Server, you can just spool up SQL Server Profiler and compare the queries and execution plans.

    As with any performance issue, you must measure first. With your scenario, you have to do more. You have to measure twice with each technology and make sure you are comparing apples to apples. If you can rule out the sql being generated you will then have to measure the application code, to possibly rule any bottlenecks there.

    I suspect it will be the generated queries though.

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

Sidebar

Related Questions

Okay, I know I'm doing something wrong - but can't figure out a better
Okay, I know this question have been asked plenty of times already, but I
Okay the question title may not have made sense... mostly because I don't know
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay, I really know this has GOT to be the long way around doing
Okay, I have been researching on how to do this, but say I am
Okay i know i have to use the JDBC etc, but im not sure
Okay I know I asked about this before, and the answer was basically cache
Okay. I know this looks like the typical Why didn't he just Google it
Okay, we know that the following two lines are equivalent - (0 == i)

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.