using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace Mvc4_TESTID2.Models
{
public class TestID2
{
[Required(ErrorMessage="Please enter the MO Number")]
public Int64 MoNo { get; set; }
[Required(ErrorMessage="Please enter the MainSerNo")]
public string MainSerNo { get; set; }
public static List<PPL_PRODUCT_TESTID2> ListTestID2()
{
using (TESTID2Entities context = new TESTID2Entities())
{
var query =
from products in context.PPL_PRODUCT_TESTID2
where products.MONO == 5656303 && products.MAINSERNO == "40000020159391" // not to be hardcoded.
select products;
return query.ToList();
}
}
public static List<PPL_PRODUCT_TESTID2> SelectTestID2(Int64 MONO, string MAINSERNO)
{
using (TESTID2Entities context = new TESTID2Entities())
{
var query =
from products in context.PPL_PRODUCT_TESTID2
where products.MONO == MONO && products.MAINSERNO == MAINSERNO
select products;
return query.ToList();
}
}
}
}
http://localhost:50893/TestID2/SelectTestID2 takes some time to load in the browser, and when I key in those values for MONO and MAINSERNO and press the Submit button, 3 rows of correct data comes
out, but it takes too much longer time.
both are similiar to each other.. why NorthWind has no issue , and the other database it has issue in speed?
Are not. You are seleting from different tables. What if one have 1 row, and another have 1.000.000.000 rows? ( and I have not started the discussion about memory, hard disk, indexes and another)
sure enough..I should not compare one database with another database.
Let us say now I am doing dealing with ONE Oracle database of rows 16053329
With ListTestID2 (MONO and MAINSERNO being hardcoded), I am able to retrieve the data almost instantly.
public static List<PPL_PRODUCT_TESTID2> ListTestID2()
{
DateTime start = new DateTime(2012,1,18);
using (TESTID2Entities context = new TESTID2Entities())
{
var query =
from products in context.PPL_PRODUCT_TESTID2
where products.MONO == 5656303 && products.MAINSERNO == "40000020159391" // not to be hardcoded.
select products;
return query.ToList();
}
}
But with SelectTestID2 (which MONO and MAINSERNO is input from HTML Textboxes), it is tortoise-slow speed in retrieving the data. Even the webpage takes unreasonable long time to load up.
public static List<PPL_PRODUCT_TESTID2> SelectTestID2(Int64 MONO, string MAINSERNO)
{
using (TESTID2Entities context = new TESTID2Entities())
{
var query =
from products in context.PPL_PRODUCT_TESTID2
where products.MONO == MONO && products.MAINSERNO == MAINSERNO
select products;
return query.ToList();
}
}
I do not believe it too. That is the reason why I tested the similar code with the Northwind local database, which do not have such issue.
Answers to your questions:
(1) Yes, they are using the SAME database and SAME table (as you can see from my code) and same input values of MONO=5656303 and MAINSERNO=40000020159391.
Both outputs show the same identical data. But the one who gets its input from HTML Textboxes gets some time to load up its page, and some unreasonable time to load the correct data. I am just puzzled.
Could you advise how do I put a stopwatch and see the results?
kelvin tan
Member
50 Points
95 Posts
Am I doing the correct thing for MVC?
Feb 21, 2013 10:35 PM|LINK
I have this for my Model:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; namespace Mvc4_TESTID2.Models { public class TestID2 { [Required(ErrorMessage="Please enter the MO Number")] public Int64 MoNo { get; set; } [Required(ErrorMessage="Please enter the MainSerNo")] public string MainSerNo { get; set; } public static List<PPL_PRODUCT_TESTID2> ListTestID2() { using (TESTID2Entities context = new TESTID2Entities()) { var query = from products in context.PPL_PRODUCT_TESTID2 where products.MONO == 5656303 && products.MAINSERNO == "40000020159391" // not to be hardcoded. select products; return query.ToList(); } } public static List<PPL_PRODUCT_TESTID2> SelectTestID2(Int64 MONO, string MAINSERNO) { using (TESTID2Entities context = new TESTID2Entities()) { var query = from products in context.PPL_PRODUCT_TESTID2 where products.MONO == MONO && products.MAINSERNO == MAINSERNO select products; return query.ToList(); } } } }and 2 Views as below:
@model IEnumerable<Mvc4_TESTID2.PPL_PRODUCT_TESTID2> @{ ViewBag.Title = "ListTestID2"; } <h2>ListTestID2</h2> <table> <tr> <th> @Html.DisplayNameFor(model => model.ID) </th> <th> @Html.DisplayNameFor(model => model.MAINSERNO) </th> <th> @Html.DisplayNameFor(model => model.SUBSERNO) </th> <th> @Html.DisplayNameFor(model => model.MONO) </th> <th> @Html.DisplayNameFor(model => model.ITNO) </th> <th> @Html.DisplayNameFor(model => model.TESTMODE) </th> <th> @Html.DisplayNameFor(model => model.TIMESTAMP) </th> <th> @Html.DisplayNameFor(model => model.TESTTIME) </th> <th> @Html.DisplayNameFor(model => model.SYSTEMTYPE) </th> <th> @Html.DisplayNameFor(model => model.TESTFILE) </th> <th> @Html.DisplayNameFor(model => model.SERVERID) </th> <th> @Html.DisplayNameFor(model => model.TESTINST) </th> <th> @Html.DisplayNameFor(model => model.TESTFLAG) </th> <th> @Html.DisplayNameFor(model => model.OPNO) </th> <th> @Html.DisplayNameFor(model => model.LASTUPDATE) </th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ID) </td> <td> @Html.DisplayFor(modelItem => item.MAINSERNO) </td> <td> @Html.DisplayFor(modelItem => item.SUBSERNO) </td> <td> @Html.DisplayFor(modelItem => item.MONO) </td> <td> @Html.DisplayFor(modelItem => item.ITNO) </td> <td> @Html.DisplayFor(modelItem => item.TESTMODE) </td> <td> @Html.DisplayFor(modelItem => item.TIMESTAMP) </td> <td> @Html.DisplayFor(modelItem => item.TESTTIME) </td> <td> @Html.DisplayFor(modelItem => item.SYSTEMTYPE) </td> <td> @Html.DisplayFor(modelItem => item.TESTFILE) </td> <td> @Html.DisplayFor(modelItem => item.SERVERID) </td> <td> @Html.DisplayFor(modelItem => item.TESTINST) </td> <td> @Html.DisplayFor(modelItem => item.TESTFLAG) </td> <td> @Html.DisplayFor(modelItem => item.OPNO) </td> <td> @Html.DisplayFor(modelItem => item.LASTUPDATE) </td> </tr> } </table>@model IEnumerable<Mvc4_TESTID2.PPL_PRODUCT_TESTID2> @{ ViewBag.Title = "SelectTestID2"; } <html> <head> <title>SelectTestID2</title> </head> <body> @using (Html.BeginForm()) { @Html.ValidationSummary() <p> MONO: @Html.TextBoxFor(m => m.FirstOrDefault().MONO) For example: 4222452 </p> <p> MAINSERNO:@Html.TextBoxFor(m=> m.FirstOrDefault().MAINSERNO) For example: 40000016292349</p> <input type="submit" value="Submit" /> } </body> </html> <table> <tr> <th> @Html.DisplayNameFor(model => model.ID) </th> <th> @Html.DisplayNameFor(model => model.MAINSERNO) </th> <th> @Html.DisplayNameFor(model => model.SUBSERNO) </th> <th> @Html.DisplayNameFor(model => model.MONO) </th> <th> @Html.DisplayNameFor(model => model.ITNO) </th> <th> @Html.DisplayNameFor(model => model.TESTMODE) </th> <th> @Html.DisplayNameFor(model => model.TIMESTAMP) </th> <th> @Html.DisplayNameFor(model => model.TESTTIME) </th> <th> @Html.DisplayNameFor(model => model.SYSTEMTYPE) </th> <th> @Html.DisplayNameFor(model => model.TESTFILE) </th> <th> @Html.DisplayNameFor(model => model.SERVERID) </th> <th> @Html.DisplayNameFor(model => model.TESTINST) </th> <th> @Html.DisplayNameFor(model => model.TESTFLAG) </th> <th> @Html.DisplayNameFor(model => model.OPNO) </th> <th> @Html.DisplayNameFor(model => model.LASTUPDATE) </th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ID) </td> <td> @Html.DisplayFor(modelItem => item.MAINSERNO) </td> <td> @Html.DisplayFor(modelItem => item.SUBSERNO) </td> <td> @Html.DisplayFor(modelItem => item.MONO) </td> <td> @Html.DisplayFor(modelItem => item.ITNO) </td> <td> @Html.DisplayFor(modelItem => item.TESTMODE) </td> <td> @Html.DisplayFor(modelItem => item.TIMESTAMP) </td> <td> @Html.DisplayFor(modelItem => item.TESTTIME) </td> <td> @Html.DisplayFor(modelItem => item.SYSTEMTYPE) </td> <td> @Html.DisplayFor(modelItem => item.TESTFILE) </td> <td> @Html.DisplayFor(modelItem => item.SERVERID) </td> <td> @Html.DisplayFor(modelItem => item.TESTINST) </td> <td> @Html.DisplayFor(modelItem => item.TESTFLAG) </td> <td> @Html.DisplayFor(modelItem => item.OPNO) </td> <td> @Html.DisplayFor(modelItem => item.LASTUPDATE) </td> </tr> } </table>And Controller:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Mvc4_TESTID2.Models; namespace Mvc4_TESTID2.Controllers { public class TestID2Controller : Controller { // // GET: /TestID2/ public ActionResult Index() { return View(); } public ActionResult ListTestID2() { return View(TestID2.ListTestID2()); } public ViewResult SelectTestID2() { if (ModelState.IsValid) { Int64 MoNo = Convert.ToInt64(Request.Form["MoNo"]); string MainSerNo = Request.Form["MainSerNo"]; return View(TestID2.SelectTestID2(MoNo, MainSerNo)); } else { return View(); } } } }Problem is this:
http://localhost:50893/TestID2/ListTestID2 is able to load in this data from database almost instantly. There are 17 rows of such data.
http://localhost:50893/TestID2/SelectTestID2 takes some time to load in the browser, and when I key in those values for MONO and MAINSERNO and press the Submit button, 3 rows of correct data comes out, but it takes too much longer time.
ignatandrei
All-Star
135184 Points
21682 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 02:31 AM|LINK
1.
1.a) You call in ModelState.IsValid without having a Model
1.b) Usually,ModelState.IsValid is calling in POST
1.c) You call Request.Form in GET action - no result
1.d) Maybe TestID2.SelectTestID2(MoNo, MainSerNo) takes some time.
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 04:28 AM|LINK
with this
public ViewResult SelectTestID2() { Int64 MoNo = Convert.ToInt64(Request.Form["MoNo"]); string MainSerNo = Request.Form["MainSerNo"]; return View(TestID2.SelectTestID2(MoNo, MainSerNo)); }the speed is also significantly slow.
However, with this
public ViewResult SelectNorthWind() { if (ModelState.IsValid) { string Country = Request.Form["Country"]; return View(NorthWind.SelectNorthWind(Country)); } else { return View(); } }for NorthWind database, there is no issue in speed.
ossprologix
Member
392 Points
127 Posts
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 05:25 AM|LINK
Inspect the query generated maybe it's the query
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 06:00 AM|LINK
but both are similiar to each other.. why NorthWind has no issue , and the other database it has issue in speed?
NorthWind is in my local PC while the other is the Oracle database in server. but that should not be any issue also, correct?
ignatandrei
All-Star
135184 Points
21682 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 06:47 AM|LINK
Are not. You are seleting from different tables. What if one have 1 row, and another have 1.000.000.000 rows? ( and I have not started the discussion about memory, hard disk, indexes and another)
You compare apples with oranges.
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 07:18 AM|LINK
sure enough..I should not compare one database with another database.
Let us say now I am doing dealing with ONE Oracle database of rows 16053329
With ListTestID2 (MONO and MAINSERNO being hardcoded), I am able to retrieve the data almost instantly.
public static List<PPL_PRODUCT_TESTID2> ListTestID2() { DateTime start = new DateTime(2012,1,18); using (TESTID2Entities context = new TESTID2Entities()) { var query = from products in context.PPL_PRODUCT_TESTID2 where products.MONO == 5656303 && products.MAINSERNO == "40000020159391" // not to be hardcoded. select products; return query.ToList(); } }But with SelectTestID2 (which MONO and MAINSERNO is input from HTML Textboxes), it is tortoise-slow speed in retrieving the data. Even the webpage takes unreasonable long time to load up.
public static List<PPL_PRODUCT_TESTID2> SelectTestID2(Int64 MONO, string MAINSERNO) { using (TESTID2Entities context = new TESTID2Entities()) { var query = from products in context.PPL_PRODUCT_TESTID2 where products.MONO == MONO && products.MAINSERNO == MAINSERNO select products; return query.ToList(); } }So what is the main issue in this?
ignatandrei
All-Star
135184 Points
21682 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 08:55 AM|LINK
1 . I do not believe.Are you sure that you are using the same database and the same values?
2. It is not a MVC thing
3. put a StopWatch and say the results.
ossprologix
Member
392 Points
127 Posts
Re: Am I doing the correct thing for MVC?
Feb 22, 2013 03:41 PM|LINK
execute the same request in ur remote server.. which means login to ur remote server and execute request.. cud be bandwidth issue
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 24, 2013 06:02 AM|LINK
Dear Ignatandrei,
I do not believe it too. That is the reason why I tested the similar code with the Northwind local database, which do not have such issue.
Answers to your questions:
(1) Yes, they are using the SAME database and SAME table (as you can see from my code) and same input values of MONO=5656303 and MAINSERNO=40000020159391.
Both outputs show the same identical data. But the one who gets its input from HTML Textboxes gets some time to load up its page, and some unreasonable time to load the correct data. I am just puzzled.
Could you advise how do I put a stopwatch and see the results?