实体框架没有返回的问题

时间:2017-03-15 16:56:30

标签: c# entity-framework linq linq-to-sql linq-to-entities

所以我昨天遇到了一个问题,我已经完成并提高了程序的速度,但是我遇到了一个问题,我从来没有遇到过返回断点,也没有例外。此查询可以一次运行多次,具体取决于运行所需的计划时间,但如果我与一家公司单独运行它,则可以正常运行。知道为什么吗?

try
{
    //work on query further , need to get client ID correctly
    if (vehicleses.Count == 0)
        return null;
    string siteId = QueryExportSiteWithId(exportSiteId).SiteId;
    string clientId = vehicleses[0].ClientID;

    var inventoryyReturn = from i in db.Inventory_Vehicles
        where dealerIdList.Any(c => c == i.ClientID) && i.Archived != "1" && i.Holding != "1" &&
              i.Status == "A"
        select i;

    var inventoryDescription = from i in db.Inventory_Descriptions
        where
        inventoryyReturn.Any(
            c => new {client = c.ClientID, inv = c.ID} == new {client = i.ClientID, inv = i.InventoryID})
        select i;
    var settingsExports = from i in db.Settings_Exports
        where inventoryyReturn.Any(c => c.ClientID == i.ClientID)
        select i;
    var settingLots = from i in db.Settings_Lots
        where
        inventoryyReturn.Any(
            c => new {client = c.ClientID, lot = c.LotID} == new {client = i.ClientID, lot = i.ID})
        select i;
    var inventoryFeatures = from i in db.Inventory_Features
        where
        inventoryyReturn.Any(
            c => new {client = c.ClientID, inv = c.ID} == new {client = i.ClientID, inv = i.InventoryID})
        select i;
    var inventoryPhotos = from i in db.Inventory_Photos
        where
        inventoryyReturn.Any(c => c.ID == i.InventoryID)
        select i;


    var longReturnListt = await (from i in inventoryyReturn
        join l in inventoryDescription on new {inv = i.ID, cli = i.ClientID} equals
        new {inv = l.InventoryID, cli = l.ClientID} into descGroup
        from m in descGroup.DefaultIfEmpty()
        join s in settingsExports on i.ClientID equals s.ClientID into settingGroup
        from sg in settingGroup.DefaultIfEmpty()
        join sl in settingLots on new {client = sg.ClientID, lot = sg.LotID} equals
        new {client = sl.ClientID, lot = sl.ID} into lotsGroup
        from lg in lotsGroup.DefaultIfEmpty()
        join se in db.Settings_ExportSites on new {client = lg.ClientID, lotId = i.LotID, site = siteId}
        equals new {client = se.ClientID, lotId = se.LotID, site = se.Site} into exportGroup
        from eg in exportGroup.DefaultIfEmpty()
        join f in inventoryFeatures on new {inv = i.ID, cli = i.ClientID} equals
        new {inv = f.InventoryID, cli = f.ClientID} into invFeatGroup
        from ifg in invFeatGroup.DefaultIfEmpty()
        join p in inventoryPhotos on i.ID equals p.InventoryID into photo
        from photos in photo.DefaultIfEmpty()
        orderby i.ID
        select new {i, m, sg, photoo = photo.ToList(), lg, ifg, eg}
        into grouped

        //  group grouped by new {grouped.i.ClientID } into groupedDone
        // select groupedDone
        select new NewType
        {
            InventoryVehicles = grouped.i,
            InventoryDescriptions = grouped.m,
            SettingsExports = grouped.sg,
            InventoryPhotos = grouped.photoo,
            SettingsLots = grouped.lg,
            InventoryFeatures = grouped.ifg,
            SettingsExportSites = grouped.eg
        }
    ).AsNoTracking().ToListAsync();

    if (longReturnListt != null) returnList.AddRange(longReturnListt);
}
catch (Exception exception)
{
    Console.WriteLine(exception);
    throw;
}

return returnList;

0 个答案:

没有答案