Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="isReadOnly"></param>
 protected AbstractEntity(bool isReadOnly)
     : base(isReadOnly)
 {
     _isNew    = true;
     IsInCache = false;
     if (EntitySchemaSet.TryGet(GetType(), out _schema))
     {
         _isReadOnly = _schema.AccessLevel == AccessLevel.ReadOnly;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 获得实体DB架构信息
        /// </summary>
        /// <returns>返回值会为Null</returns>
        public SchemaTable GetSchema()
        {
            SchemaTable schemaTable;
            Type        type = GetType();

            if (!EntitySchemaSet.TryGet(type, out schemaTable))
            {
                //若实体架构信息为空,则重新加载架构信息
                EntitySchemaSet.InitSchema(type);
                if (!EntitySchemaSet.TryGet(type, out schemaTable))
                {
                    TraceLog.WriteError("Class:{0} scheam is not setting.", type.FullName);
                }
            }
            return(schemaTable);
        }
Esempio n. 3
0
        /// <summary>
        /// Set key from keycode
        /// </summary>
        /// <param name="keyCode"></param>
        /// <param name="typeName"></param>
        internal void SetKeyValue(string keyCode, string typeName)
        {
            SchemaTable schemaTable;

            if (EntitySchemaSet.TryGet(typeName, out schemaTable))
            {
                string[] keyValues = DecodeKeyCode(keyCode).Split(KeyCodeJoinChar);
                for (int i = 0; i < schemaTable.Keys.Length; i++)
                {
                    string columnName = schemaTable.Keys[i];
                    var    colAttr    = schemaTable[columnName];
                    if (i < keyValues.Length && colAttr != null)
                    {
                        object value = ParseValueType(keyValues[i], colAttr.ColumnType);
                        SetPropertyValue(columnName, value);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取实体KEY
        /// </summary>
        /// <returns></returns>
        public string GetKeyCode()
        {
            string      value = KeyValue;
            SchemaTable entitySchema;

            if (EntitySchemaSet.TryGet(GetType(), out entitySchema))
            {
                foreach (string key in entitySchema.Keys)
                {
                    if (value.Length > 0)
                    {
                        value += KeyCodeJoinChar;
                    }
                    value += EncodeKeyCode(GetPropertyValue(key).ToNotNullString());
                }
                if (string.IsNullOrEmpty(value))
                {
                    TraceLog.WriteError("Entity {0} primary key is empty.", entitySchema.EntityName);
                }
            }

            return(value);
        }