Exemple #1
0
 /// <summary>
 /// 创建数据表元数据。
 /// </summary>
 /// <param name="itemType">数据项CLR类型。</param>
 /// <param name="attr">表的特性。</param>
 /// <param name="engine">元数据引擎。</param>
 public TableMetadata(Type itemType, TableAttribute attr, MetadataEngine engine)
     : this(itemType, attr.Name, engine, attr.MapInheritedProperties)
 {
     if (!string.IsNullOrEmpty(attr.Schema))
     {
         Schema = attr.Schema;
     }
 }
Exemple #2
0
        /// <summary>
        /// 创建数据表元数据。
        /// </summary>
        /// <param name="itemType">数据项CLR类型。</param>
        /// <param name="name">强制表名 。</param>
        /// <param name="engine">元数据引擎。</param>
        /// <param name="inheritedProperties">是否继承父级属性。</param>
        public TableMetadata(Type itemType, string name, MetadataEngine engine, bool inheritedProperties = true)
            : base(itemType, engine)
        {
            Name = name;
            var columns = InitialMembers(itemType, inheritedProperties, out TableMetadata keyOwner);

            if (keyOwner == this)
            {
                Keys = InitialKeys(keyOwner, ref columns);
            }
            else
            {
                Keys = keyOwner.Keys;
            }
            Members = new MemberCollection <ColumnMetadata>(columns);
            RefreshConcurrencys();
        }
Exemple #3
0
        /// <summary>
        /// 创建类型元数据。
        /// </summary>
        /// <param name="itemType">数据项的CLR类型。</param>
        /// <param name="engine">元数据引擎。</param>
        public TypeMetadata(Type itemType, MetadataEngine engine)
            : base(itemType, engine)
        {
            ComplexMembers = new MemberCollection <MemberMetadata>();
            List <MemberMetadata> primarys = null;

            if (itemType.IsAnonymous())
            {
                var constructor = itemType.GetConstructors()[0];
                var parameters  = constructor.GetParameters();
                var query       = from a in parameters
                                  join b in itemType.GetProperties() on a.ParameterType equals b.PropertyType
                                  select b;
                foreach (var property in query)
                {
                    var propertyType = property.PropertyType;
                    if (propertyType.IsComplexCollection())
                    {
                        ComplexMembers.Add(new MemberMetadata(property, MemberKind.Collection));
                    }
                    else if (propertyType.IsObject())
                    {
                        ComplexMembers.Add(new MemberMetadata(property, MemberKind.Object));
                    }
                }
                primarys = itemType.GetProperties()
                           .Where(a => a.PropertyType.IsPrimary()).Sort()
                           .Select(a => new MemberMetadata(a, MemberKind.Primary)).ToList();
            }
            else
            {
                foreach (var property in itemType.GetProperties().Sort())
                {
                    var propertyType = property.PropertyType;
                    if (propertyType.IsComplexCollection())
                    {
                        ComplexMembers.Add(new MemberMetadata(property, MemberKind.Collection));
                    }
                    else if (propertyType.IsObject())
                    {
                        ComplexMembers.Add(new MemberMetadata(property, MemberKind.Object));
                    }
                }
                var table = engine.TryGetTable(itemType);
                if (table.InheritSets.Length == 0)
                {
                    primarys = table.Members.Select(a => new MemberMetadata(a.Member, MemberKind.Primary)).ToList();
                }
                else
                {
                    primarys = table.InheritSets
                               .SelectMany(a => a.Members)
                               .Union(table.Members).Select(b => new MemberMetadata(b.Member, MemberKind.Primary)).ToList();
                }
                KeyIndexs = new int[table.Keys.Length];
                for (int i = 0; i < KeyIndexs.Length; i++)
                {
                    KeyIndexs[i] = i;
                }
            }
            PrimaryMembers = new MemberCollection <MemberMetadata>(primarys);
        }
Exemple #4
0
 /// <summary>
 /// 创建类型元数据基类。
 /// </summary>
 /// <param name="itemType">CLR类型。</param>
 /// <param name="engine">元数据引擎。</param>
 public TypeMetadataBase(Type itemType, MetadataEngine engine)
 {
     Engine  = engine;
     ClrType = itemType;
 }