This is a migrated thread and some comments may be shown as answers.

application is very slow

2 Answers 165 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
pratik
Top achievements
Rank 1
pratik asked on 06 Jul 2009, 06:32 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
PetarP
Telerik team
answered on 09 Jul 2009, 02:05 PM
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.
0
pratik
Top achievements
Rank 1
answered on 10 Jul 2009, 10:44 AM
thanks........................ It really helps......
Tags
Data Access Free Edition
Asked by
pratik
Top achievements
Rank 1
Answers by
PetarP
Telerik team
pratik
Top achievements
Rank 1
Share this question
or