Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我的Asp.NETMVC页面需要12秒。装载_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

C# 我的Asp.NETMVC页面需要12秒。装载

C# 我的Asp.NETMVC页面需要12秒。装载,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我有一个像这样的MVC控制器 public ActionResult Index(int vendor=-1, int product = -1, string error="", string mode="Shortfall") { if (Session["UserId"] == null) return RedirectToAction("Index", "Login"); var products = DbContext.G

我有一个像这样的MVC控制器

public ActionResult Index(int vendor=-1, int product = -1, string error="", string mode="Shortfall")
    {
        if (Session["UserId"] == null)
            return RedirectToAction("Index", "Login");
        var products = DbContext.GetAllProducts();
        List<SurplusViewModel> surplusList = new List<SurplusViewModel>();
        Dictionary<int, string> searchVendor = new Dictionary<int, string>();
        Dictionary<int, string> searchProds = new Dictionary<int, string>();
        if (products.Count() > 0)
        {
            foreach (var prod in products)
            {
                SurplusViewModel s = new SurplusViewModel(prod);
                surplusList.Add(s);
                foreach (var v in s.Vendors)
                {
                    if (!searchVendor.ContainsKey(v.CorpId))
                    {
                        searchVendor.Add(v.CorpId, v.CorpName);
                    }
                }
                if(!searchProds.ContainsKey(s.ProductId))
                    searchProds.Add(s.ProductId, s.ProductVM.ProductCode + " / " + s.ProductVM.ProductPartNo);
            }
        }
        ViewData["vendorList"] = searchVendor;
        ViewData["productList"] = searchProds;
        ViewData["selectVendor"] = vendor;
        ViewData["selectProd"] = product;
        ViewData["mode"] = mode;
        ViewBag.Message = "";
        ViewBag.Error = "";
        IEnumerable<SurplusViewModel> finalList = surplusList.OrderBy(o => o.Difference).ToList();
        if (vendor > 0)
        {
            Corporation searchcorp = DbContext.GetCorporation(vendor);
            finalList = finalList.Where(x => x.VendorNames.IndexOf(searchcorp.CorpName) >= 0);
        }
        if (product > 0)
        {
            finalList = finalList.Where(x => x.ProductId == product);
        }
        if (vendor < 0 && product < 0)
        {
            if (mode.Equals("Shortfall"))
                finalList = finalList.Where(f => f.VendorQuantity - (f.CMQuantity + f.OEMQuantity) < 0);
            else if (mode.Equals("Surplus"))
                finalList = finalList.Where(f => f.VendorQuantity - (f.CMQuantity + f.OEMQuantity) > 0);


        }
        return View(finalList);
        //return View();
    }
public-ActionResult索引(int-vendor=-1,int-product=-1,string-error=,string-mode=“短缺”)
{
if(会话[“UserId”]==null)
返回重定向操作(“索引”、“登录”);
var products=DbContext.GetAllProducts();
列表剩余列表=新列表();
Dictionary searchVendor=新字典();
Dictionary searchProds=新建字典();
如果(products.Count()>0)
{
foreach(产品中的var产品)
{
盈余视图模型s=新盈余视图模型(prod);
盈余清单。添加(s);
foreach(美国供应商的var v)
{
如果(!searchVendor.ContainsKey(v.CorpId))
{
searchVendor.Add(v.CorpId,v.CorpName);
}
}
如果(!searchProds.ContainsKey(s.ProductId))
searchProds.Add(s.ProductId,s.ProductVM.ProductCode+“/”+s.ProductVM.ProductPartNo);
}
}
ViewData[“供应商列表”]=搜索供应商;
ViewData[“productList”]=searchProds;
ViewData[“selectVendor”]=供应商;
ViewData[“selectProd”]=产品;
ViewData[“模式”]=模式;
ViewBag.Message=“”;
ViewBag.Error=“”;
IEnumerable finalList=盈余列表.OrderBy(o=>o.Difference.ToList();
如果(供应商>0)
{
Corporation searchcorp=DbContext.GetCorporation(供应商);
finalList=finalList.Where(x=>x.VendorNames.IndexOf(searchcorp.CorpName)>=0);
}
如果(产品>0)
{
finalList=finalList.Where(x=>x.ProductId==product);
}
if(供应商<0和产品<0)
{
if(模式等于(“差额”))
finalList=finalList,其中(f=>f.VendorQuantity-(f.CMQuantity+f.OEMQuantity)<0);
else if(模式等于(“盈余”))
finalList=finalList,其中(f=>f.VendorQuantity-(f.CMQuantity+f.OEMQuantity)>0);
}
返回视图(finalList);
//返回视图();
}
在本地主机上加载大约需要20秒。我可以做些什么来提高我的应用程序的加载时间。如果在本地主机上需要20秒,我想在互联网上速度会非常慢。有什么建议吗

编辑:盈余视图模型的代码

public SurplusViewModel(Product product)
    {
        int productId = product.ProductId;
        ProductId = productId;
        ProductVM = new ProductViewModel(product);
        var saleDetsCM = from s in DbContext.GetSalesOrderDetailsFromCM()
                         where s.ProductId == productId && s.SaleStatus.Equals("Open") && (s.OrderType.ToLower().Equals("prototype") || s.OrderType.ToLower().Equals("production"))
                         orderby s.SalDetId descending
                         select s;

        var saleDetsOEM = from s in DbContext.GetSalesOrderDetailsFromOEMs()
                          where s.ProductId == productId && s.SaleStatus.Equals("Open") && (s.OrderType.ToLower().Equals("prototype") || s.OrderType.ToLower().Equals("production"))
                          orderby s.SalDetId descending
                          select s;

        var shipQty = from s in DbContext.GetAllSalesDets()
                      where s.ProductId == productId && !s.SaleStatus.Equals("Open") && (s.OrderType.ToLower().Equals("prototype") || s.OrderType.ToLower().Equals("production"))
                      orderby s.SalDetId descending
                      select s;

        CustomerOrdersFromCMs = saleDetsCM.ToList();
        CustomerOrdersFromOEMs = saleDetsOEM.ToList();
        VendorOrders = (from p in DbContext.GetPurchaseDetsForProduct(productId)
                        where p.OrderType != null && (p.OrderType.ToLower().Equals("prototype") || p.OrderType.ToLower().Equals("production"))
                        select p).ToList();
        var poIds = from v in VendorOrders
                     select v.PodPOId;
        BatchPurchaseDetails = DbContext.GetBatchPurchaseForProduct(productId).ToList();
        VendorOrderCount = 0;
        VendorQuantity = 0;
        var purchaseOrds = (from po in DbContext.GetPurchaseOrdersForProduct(productId)
                            where poIds.Contains(po.POId)
                            select po).ToList();
        List<int> vendIds = new List<int>();
        foreach (var po in purchaseOrds)
        {
            vendIds.Add(po.VendorId.Value);
        }
        var vendors = from v in DbContext.GetAllCorps()
                      where vendIds.Contains(v.CorpId)
                      select v;

        foreach (var podet in VendorOrders)
        {
            double totalbatchqty = 0;
            var purdetBatch = DbContext.GetBatchDetailsForPurchaseDet(podet.PodId);
            VendorQuantity += podet.Quantity;
            foreach (var b in purdetBatch)
            {
                totalbatchqty += b.Quantity;
                VendorQuantity -= b.Quantity;
            }
            if (totalbatchqty >= podet.Quantity)
            {

            }
            else
            {
                VendorOrderCount++;
            }

        }

        Vendors = vendors.ToList();
        VendorNames = "";
        foreach (var vnd in Vendors)
        {
            VendorNames += vnd.CorpName + ",";
        }
        if (VendorNames.Length > 0)
        {
            VendorNames = VendorNames.Substring(0, VendorNames.Length - 1);
        }


        OEMQuantity = 0;
        foreach (var item in CustomerOrdersFromOEMs)
        {
            OEMQuantity += item.Quantity;
        }

        CMQuantity = 0;
        foreach (var item in CustomerOrdersFromCMs)
        {
            CMQuantity += item.Quantity;
        }
        ShipQuantity = 0;
        foreach (var item in shipQty)
        {
            ShipQuantity += item.Quantity;
        }
        Difference = VendorQuantity - (CMQuantity + OEMQuantity);
        //TotalInsideSalesOrder = VendorOrders.Count();

    }
公共盈余视图模型(产品)
{
int productId=product.productId;
ProductId=ProductId;
ProductVM=新产品视图模型(产品);
var saleDetsCM=来自DbContext.GetSalesOrderDetailsFromCM()中的s
其中s.ProductId==ProductId&&s.SaleStatus.Equals(“开放”)&&(s.OrderType.ToLower().Equals(“原型”)| | s.OrderType.ToLower().Equals(“生产”))
索氏按蚊
选择s;
var saleDetsOEM=来自DbContext.GetSalesOrderDetailsFromOEMs()中的s
其中s.ProductId==ProductId&&s.SaleStatus.Equals(“开放”)&&(s.OrderType.ToLower().Equals(“原型”)| | s.OrderType.ToLower().Equals(“生产”))
索氏按蚊
选择s;
var shipQty=来自DbContext.GetAllSalesDets()中的
其中s.ProductId==ProductId&!s.SaleStatus.Equals(“开放”)&&(s.OrderType.ToLower().Equals(“原型”)| | s.OrderType.ToLower().Equals(“生产”))
索氏按蚊
选择s;
CustomerOrdersFromCMs=saleDetsCM.ToList();
CustomerOrdersFromOEM=saleDetsOEM.ToList();
VendorOrders=(来自DbContext.GetPurchaseDetsForProduct(productId)中的p)
其中p.OrderType!=null&(p.OrderType.ToLower().Equals(“原型”)| | p.OrderType.ToLower().Equals(“生产”))
选择p.ToList();
var POID=从v到供应商订单
选择v.PodPOId;
BatchPurchaseDetails=DbContext.GetBatchPurchaseForProduct(productId).ToList();
VendorOrderCount=0;
供应商数量=0;
var purchaseOrds=(来自DbContext.GetPurchaseOrdersForProduct(productId)中的po)
其中POId.Contains(po.POId)
选择po.ToList();
List vendIds=新列表();
foreach(采购订单中的var po)
{
添加(采购订单VendorId.Value);
}
var vendors=来自DbContext.GetAllCorps()中的v
其中vendIds.Contains(v.CorpId)
选择v;
foreach(供应商订单中的var podet)
{
double totalbatchqty=0;
var purdetBatch=DbContext.GetBatchDetailsForPurchaseDet(podet.PodId);
供应商数量+=订单数量;
foreach(purdetBatch中的变量b)
{
totalbatchqty+=b.数量;
供应商数量-=b.数量;
}
如果(totalbatchqty>=podet.数量)
{
}
其他的
{
VendorOrderCount++;
}
}
Vendors=Vendors.ToList();
VendorNames=“”;
foreach(供应商中的var vnd)
{
VendorNames+=vnd.CorpName+“,”;
}
如果(VendorNames.Length>0)
{
VendorNames=VendorNames.Substring(0,VendorNames.Length-1);
}
OEMQuantity=0;
foreach(原始设备制造商的客户订单中的var项目)
{
OEMQuantity+=物料数量;
}
CMQuantity=0;
foreach(CustomerOrdersFromCMs中的var项)
{
CMQuantity+=物料数量;
}
发货数量=0;
foreach(发货数量中的var项目)
{
发货数量+=项目数量;