1

キャッシュに使用したいLinq DataContextの周りにDecoratorがあります。リポジトリは、マップされたデータベース タイプの 1 つの IQueryable を返します。私の意図がパフォーマンスを向上させることであった場合、これは良い考えですか? メソッドが List からの IQueryable を返す場合もあれば、DataContext から直接返される場合もあります。この構成では、一部のクエリが Stackoverflowexception でクラッシュします。

クエリ:

         IDataContext ctx = DataContextFactory.ctx();
     IQueryable<PositionsVF> positions = from p in ctx.Repository<PositionsVF>()
                                         from c in ctx.Repository<ConfigurationPortefeuillesModule>()

                                         where c.Module.Module1 == ListeModules.POSITIONS_VF.ToString() &&
                                         p.NoPortefeuille_FK == c.NoPortefeuille_FK && 
                                         p.PortefeuillesSpecialise.Categorie != "REGROUPEMENT" &&
                                         p.NoFond_FK == fonds &&
                                         p.Date == dateDonneeBD

                                         orderby c.Ordre
                                         select p;

コード:

  Dictionary<string, List<object>> CachedTables = new Dictionary<string, List<object>>();

  // Small tables which are queried against a lot.
  List<string> ShouldCache = new List<string>() { 
     //typeof(DerniersSoldesDAV).Name,
     //typeof(Fond).Name,
     //typeof(PortefeuillesSpecialise).Name,
     //typeof(PortefeuillesSuperposition).Name,
     //typeof(PositionsVF).Name,
     //typeof(PoidsACWI).Name,
     //typeof(PositionsSASMurex).Name,
     //typeof(TypesCompte).Name,
     //typeof(TypesMontant).Name,
     //typeof(Module).Name,

     typeof(CorrespondanceIndice).Name,
     typeof(CorrespondancePortefeuille).Name,
     //typeof(CorrespondancePortefeuillesPGP).Name,
     //typeof(CorrespondanceRegroupement).Name,
     //typeof(CorrespondancesPortefeuillesSuperposition).Name,

     //typeof(ConfigurationFondsModule).Name,
     //typeof(ConfigurationIndicesModule).Name,
     //typeof(ConfigurationPortefeuillesFondsModule).Name,
     //typeof(ConfigurationPortefeuillesModule).Name,

  };

  public IQueryable<T> Repository<T>() where T : class
  {
     ITable table = _context.GetTable(typeof(T));
     string typeName = typeof(T).Name;

     if (ShouldCache.Contains(typeName))
     {
        // Load the mini table.
        if (! CachedTables.ContainsKey(typeName))
        {
           var tableRows = table.Cast<T>().ToList();
           CachedTables.Add(typeName, tableRows.Cast<object>().ToList());
        }

        return CachedTables[typeName].Cast<T>().AsQueryable();
     }


     return table.Cast<T>();
  }
4

0 に答える 0