I have a EF code-first DbContext
:
public class Db : IdentityDbContext<User>
{
public Db(): base("Db")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Db, Migrations.Configuration>());
}
//content
public DbSet<UrlEntity> ContentUrls { get; set; }
public DbSet<Content> Contents { get; set; }
public DbSet<Banner> Banners { get; set; }
//item
public DbSet<ItemCat> ItemCats { get; set; }
public DbSet<Item> Items { get; set; }
public DbSet<ItemImage> ItemImages { get; set; }
//gallery
public DbSet<GalleryCat> GalleryCats { get; set; }
public DbSet<Gallery> Galleries { get; set; }
//news
public DbSet<New> News { get; set; }
protected override void OnModelCreating(DbModelBuilder mb)
{
//base
mb.Configurations.Add(new TreeBaseConfig());
mb.Configurations.Add(new CatConfig());
mb.Configurations.Add(new UrlEntityConfig());
//content
mb.Configurations.Add(new ContentConfig());
mb.Configurations.Add(new BannerConfig());
//item
mb.Configurations.Add(new ItemCatConfig());
mb.Configurations.Add(new ItemConfig());
mb.Configurations.Add(new ItemImageConfig());
//gallery
mb.Configurations.Add(new GalleryCatConfig());
mb.Configurations.Add(new GalleryConfig());
//new
mb.Configurations.Add(new NewConfig());
//link
//membership
mb.Configurations.Add(new UserConfig());
// mb.Configurations.Add(new UserInfoConfig());
base.OnModelCreating(mb);
}
}
and initialize and dispose db context in every controller:
public class HomeController : Controller
{
Db _db = new Db();
public ActionResult Aboutus() { return View(); }
public ActionResult Contactus() { return View(new ContactusDTO()); }
[...] // else action methods
protected override void Dispose(bool disposing)
{
if (disposing)
_db.Dispose();
base.Dispose(disposing);
}
Am I right in utilize and disposing db context correctly and effectively?
Actually my question is why http://www.hamkar-tamin.com take too time to loading?
- a few data are in my db
- technology I use: .net 4.5 EF 6.2 MVC 5.
- my web site work on IIS Express well.
When I want to load pages or inserting, or some simple CRUD (on one table), but it it take sometimes about thirty second or more to do.
Update:
I also ping the domain. average round trip time: 623ms, maximum 830ms, minimum 390ms
update:
Loading page is fine. response from server is slow, not for first request. every take too long? witch things are here that i must consider?
**update: **
i find out the problem is on every queries on Db. sql server version is 2008 R2.