Esempio n. 1
0
        private void Init()
        {
            foreach (PropertyInfo info in this.EntityType.GetProperties(this.BindingFlag))
            {
                object[] customAttributes = info.GetCustomAttributes(typeof(ColumnAttribute), true);
                if (customAttributes != null && customAttributes.Length > 0)
                {
                    ColumnAttribute colAttr    = customAttributes[0] as ColumnAttribute;
                    string          columnName = this.GetColumnName(colAttr.Name, info.Name);
                    DbParameter     parameter  = DbHelper.CreateParameter(columnName, colAttr.DataType, colAttr.Size);
                    this.allColumns.Add(columnName);
                    if (!colAttr.Identity)
                    {
                        this.insertColumns.Add(columnName);
                        this.insertParameters.Add(info.Name, parameter);
                    }
                    if (colAttr.PrimaryKey)
                    {
                        this.primaryKeyColumns.Add(columnName);
                        this.primaryKeyParameters.Add(info.Name, parameter);
                        this.updateParameters.Add(info.Name, parameter);
                    }
                    else
                    {
                        if (colAttr.AllowEdit)
                        {
                            this.updateColumns.Add(columnName);
                            this.updateParameters.Add(info.Name, parameter);
                        }
                    }
                }
            }

            PersistenceCache.SetListObjects(this.AllColumnsKey, this.allColumns);
            PersistenceCache.SetListObjects(this.InsertColumnsKey, this.insertColumns);
            PersistenceCache.SetListObjects(this.UpdateColumnsKey, this.updateColumns);
            PersistenceCache.SetListObjects(this.PrimaryKeyColumnsKey, this.primaryKeyColumns);
            PersistenceCache.SetDbParameters(this.InsertParametersKey, this.insertParameters);
            PersistenceCache.SetDbParameters(this.UpdateParametersKey, this.updateParameters);
            PersistenceCache.SetDbParameters(this.PrimaryKeyParametersKey, this.primaryKeyParameters);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取PersistenceResolve
        /// </summary>
        public static PersistenceResolver CreateResolver(Type entityType)
        {
            string key = string.Format("PersistenceResolver_{0}", entityType.ToString());
            PersistenceResolver resolver = PersistenceCache.GetPersistenceResolvers(key);

            if (resolver == null)
            {
                string[] temps = DbHelper.ProviderName.Split(new char[] { '.' });
                if (temps.Length > 0)
                {
                    Type type = Type.GetType(string.Format("EasySoft.Core.Persistence.RepositoryImplement.{0}PersistenceResolver", temps[temps.Length - 1]));
                    resolver            = (PersistenceResolver)Activator.CreateInstance(type);
                    resolver.EntityType = entityType;
                }
                if (resolver == null)
                {
                    throw new ArgumentNullException("PersistenceResolve");
                }
                PersistenceCache.SetPersistenceResolvers(key, resolver);
            }

            return(resolver);
        }