Esempio n. 1
0
 public static EntityMeta GetDefineInfoFromType(Type type)
 {
     if (!_cache.ContainsKey(type))
     {
         lock (lockobject)
         {
             if (!_cache.ContainsKey(type))
             {
                 EntityMeta meta = GetEntityMeta(type);
                 _cache.Add(type, meta);
             }
         }
     }
     return(_cache[type]);
 }
Esempio n. 2
0
        private static EntityMeta GetEntityMeta(Type type)
        {
            EntityMeta meta = new EntityMeta();

            meta.TableName = GetTableName(type);

            PropertyInfo[] pinfos = type.GetProperties();
            foreach (PropertyInfo p in pinfos)
            {
                ColumnAttribute attr = (ColumnAttribute)Attribute.GetCustomAttribute(p, typeof(ColumnAttribute));
                if (attr != null)
                {
                    EntityColumnMeta ecmeta = new EntityColumnMeta();
                    ecmeta.PropertyName = p.Name;
                    ecmeta.ColumnName   = attr.ColumnName;
                    ecmeta.Identity     = Attribute.GetCustomAttribute(p, typeof(IdentityAttribute)) != null;
                    ecmeta.PrimaryKey   = Attribute.GetCustomAttribute(p, typeof(PrimaryKeyAttribute)) != null;
                    meta.Columns.Add(ecmeta);
                }
            }

            return(meta);
        }