application is very slow

3 posts, 1 answers
  1. pratik
    pratik avatar
    2 posts
    Member since:
    Apr 2009

    Posted 06 Jul 2009 Link to this post

    Hi, My application is very slow. I think I am using wrong way.. please see below.
    here is my ScopeProvider class...

    public class DataCuesORMScopeProvider : IObjectScopeProvider
        {
            private Database myDatabase;
            private IObjectScope myScope;

            static private DataCuesORMScopeProvider theObjectScopeProvider1;

            /// <summary>
            /// Constructor.
            /// </summary>
            /// <remarks></remarks>
            public DataCuesORMScopeProvider()
            {
            }

          
            static public void AdjustForDynamicLoad()
            {
                if( theObjectScopeProvider1 == null )
                    theObjectScopeProvider1 = new DataCuesORMScopeProvider();

                if( theObjectScopeProvider1.myDatabase == null )
                {
                    string assumedInitialConfiguration =
                               "<openaccess>" +
                                   "<references>" +
                                       "<reference assemblyname='PLACEHOLDER' configrequired='True'/>" +
                                   "</references>" +
                               "</openaccess>";
                    System.Reflection.Assembly dll = theObjectScopeProvider1.GetType().Assembly;
                    assumedInitialConfiguration = assumedInitialConfiguration.Replace(
                                                        "PLACEHOLDER", dll.GetName().Name);
                    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                    xmlDoc.LoadXml(assumedInitialConfiguration);
                    Database db = Telerik.OpenAccess.Database.Get("SciensORMConnection",
                                                xmlDoc.DocumentElement,
                                                new System.Reflection.Assembly[] { dll } );

                    theObjectScopeProvider1.myDatabase = db;
                }
            }

           
            static public Database Database()
            {
                if( theObjectScopeProvider1 == null )
                    theObjectScopeProvider1 = new DataCuesORMScopeProvider();

                if( theObjectScopeProvider1.myDatabase == null )
                    theObjectScopeProvider1.myDatabase = Telerik.OpenAccess.Database.Get( "SciensORMConnection" );

                return theObjectScopeProvider1.myDatabase;
            }

          
            static public IObjectScope ObjectScope()
            {
                Database();

                if( theObjectScopeProvider1.myScope == null )
                    theObjectScopeProvider1.myScope = GetNewObjectScope();

                return theObjectScopeProvider1.myScope;
            }

           
            static public IObjectScope GetNewObjectScope()
            {
                Database db = Database();

                IObjectScope newScope = db.GetObjectScope();
                return newScope;
            }
        }


    and I am using follwing way to fetch the records..

            var contract = DataCuesORMScopeProvider.Database().GetObjectScope().GetOqlQuery<VARMSContract>().ExecuteList().Where(c => c.ContractID == ContractID).First();

    is it write method to run the query??

    please suggest

    Thanks

  2. Answer
    PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 09 Jul 2009 Link to this post

    Hello pratik,
    the problem comes from that you have used OQL to fetch the data and than LINQ to filter the result set. Now this is of course possible but the actually filtering is done on the client side rather than on the server side and for big amounts of data this can prove to be time consuming.  The better aproach will be to retrieve only the records that are going to be shown to the customer.
    You can use LINQ to achieve this:
    var result = (from c in ObjectScopeProvider1.GetNewObjectScope().Extent<VARMSContract>() where c.ContractID == ContractID select c).First(); 
    Or using OQL:
     IQuery query = ObjectScopeProvider1.GetNewObjectScope().GetOqlQuery("Select * from VARMSContractExtent where ContractID = $1"); 
                query.MaxResultCount = 1; 
                var result = query.Execute(ContractID); 
    Note that in the OQL example we are setting the MaxResultCount property so that we get only 1 entry as a result since there is no First() operant in OQL.

    Best wishes,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. pratik
    pratik avatar
    2 posts
    Member since:
    Apr 2009

    Posted 10 Jul 2009 Link to this post

    thanks........................ It really helps......
Back to Top