实体框架查询后没有执行任何语句

时间:2017-03-15 18:56:02

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

所以我正在使用Quartz为我的程序创建一个任务调度程序,我遇到的问题是,如果有多个作业要运行,它将重复执行相应作业的查询但是从不执行下一行。就好像它一碰到tolist()就挂起了。有什么想法吗?

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;
    db.Database.Log = Console.Write;


    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 = (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

        from categories in groupedDone
        select new NewType
        {
            InventoryVehicles = categories.i,
            InventoryDescriptions = categories.m,
            SettingsExports = categories.sg,
            InventoryPhotos = categories.photoo,
            SettingsLots = categories.lg,
            InventoryFeatures = categories.ifg,
            SettingsExportSites = categories.eg
        }
    ).ToList();
  //  var sql = ((System.Data.Entity.Core.Objects.ObjectQuery) longReturnListt as ObjectQuery);
 //   var trace = sql.ToTraceString();

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

0 个答案:

没有答案