예제 #1
0
        public static Type BuildDynamicObjectType(Relation relation)
        {
            Type baseType = null;

            if (!_cache.ContainsKey(relation.Identification))
            {
                IDbConnection             connection = DblHelper.CreateConnection();
                Dictionary <string, Type> properties = GetProprties(relation.Name);
                if (relation.Items != null)
                {
                    foreach (Relation item in relation.Items)
                    {
                        Dictionary <string, Type> subProperties = GetProprties(item.Name);;
                        Type subType     = TypeCreator.Creator(item.Name, subProperties);
                        Type genericType = typeof(List <>);
                        properties[item.Name] = genericType.MakeGenericType(subType);
                    }
                }
                baseType = TypeCreator.Creator(relation.Name + "Proxy", properties);
                _cache[relation.Identification] = baseType;
            }
            else
            {
                baseType = _cache[relation.Identification];
            }
            return(baseType);
        }
예제 #2
0
        public static object GetInstance(string instanceID, Relation relation)
        {
            IDbConnection             connection = DblHelper.CreateConnection();
            string                    sql        = string.Format(" select * from {0} where instanceID='{0}'", relation.Name, instanceID);
            Dictionary <string, Type> properties = GetProprties(relation.Name);

            foreach (Relation item in relation.Items)
            {
                Dictionary <string, Type> subProperties = GetProprties(item.Name);
                Type genericType = typeof(List <>);
                if (!_cache.ContainsKey(item.Identification))
                {
                    Type subType = TypeCreator.Creator(item.Name + "Proxy", subProperties);
                    properties[item.Name]       = genericType.MakeGenericType(subType);
                    _cache[item.Identification] = subType;
                }
                else
                {
                    properties[item.Name] = genericType.MakeGenericType(_cache[item.Identification]);
                }
            }

            Type baseType = null;

            if (!_cache.ContainsKey(relation.Identification))
            {
                baseType = TypeCreator.Creator(relation.Name + "Proxy", properties);
                _cache[relation.Identification] = baseType;
            }
            else
            {
                baseType = _cache[relation.Identification];
            }
            Object dataObject = connection.Query(baseType, sql);

            foreach (Relation item in relation.Items)
            {
                sql = string.Format(" select * from {0} where instanceID='{0}'", item.Name, instanceID);
                dataObject.SetValue(item.Name, connection.Query(_cache[item.Name], sql));
            }

            return(dataObject);
        }