Example #1
0
        private WPOType GetObjectWithDependencies <WPOType>(string fieldName, string fieldValue, int depth)
            where WPOType : WPOBaseObject
        {
            QueryFilter dependencyFilter = new QueryFilter(typeof(WPOType).CreateModelObj().TableObject);

            dependencyFilter.AddCondition(fieldName + " = " + fieldValue);
            Dictionary <string, string> dataRow = session.dbConnection.ExecuteReader(dependencyFilter).FirstOrDefault();

            bool    alreadyExist;
            WPOType obj = session.CreateOrGetObject <WPOType>(dataRow, dependencyFilter.Table, out alreadyExist);

            obj.Status  = ObjectStatus.Unchanged;
            obj.DataRow = dataRow;

            Dictionary <PropertyInfo, string> values = new Dictionary <PropertyInfo, string>();
            List <PropertyInfo> properties           = obj.GetPropertiesByAttribute <WPOColumnAttribute>();

            GetSimpleProperties(obj, dataRow, values, properties);
            obj = (WPOType)BasicMapper.MapPropertiesToObject(obj, values);
            GetRelatedObjects(obj, dataRow, properties, depth - 1);
            obj.TableObject = new WPOTableObject(obj);

            if (!alreadyExist)
            {
                session.objectsFromDatabase.Add((WPOBaseObject)obj.Clone());
            }

            return(obj);
        }
Example #2
0
        private void GetObjects()
        {
            InternalList = new List <T>();
            int depth = WPOManager.Configuration.DependencyDepth > 0 ? WPOManager.Configuration.DependencyDepth : int.MaxValue;

            try
            {
                session.dbConnection.Open();
                foreach (Dictionary <string, string> dataRow in session.dbConnection.ExecuteReader(filter))
                {
                    bool alreadyExist;
                    T    obj = session.CreateOrGetObject <T>(dataRow, filter.Table, out alreadyExist);
                    obj.Status  = ObjectStatus.Unchanged;
                    obj.DataRow = dataRow;

                    Dictionary <PropertyInfo, string> values = new Dictionary <PropertyInfo, string>();
                    List <PropertyInfo> properties           = obj.GetPropertiesByAttribute <WPOColumnAttribute>();
                    GetSimpleProperties(obj, dataRow, values, properties);
                    obj = (T)BasicMapper.MapPropertiesToObject(obj, values);
                    GetRelatedObjects(obj, dataRow, properties, depth - 1);
                    obj.TableObject = new WPOTableObject(obj);

                    if (!alreadyExist)
                    {
                        session.objectsFromDatabase.Add((WPOBaseObject)obj.Clone());
                    }

                    InternalList.Add(obj);
                }
            }
            finally
            {
                filter.Clear();
                session.dbConnection.Close();
            }
        }