Пример #1
0
 private void CreateReference(ReferenceInfo ri, EntityMeta entityMeta)
 {
     //如果它同时也是聚合子类,则也会被递归创建
     if (ri.Type == ReferenceType.Child)
     {
         ri.RefTypeMeta = this.FindOrCreateEntityMetaRecur(ri.RefType, entityMeta);
     }
     else
     {
         //以下代码转换为懒加载属性的模式。
         //this.FireAfterAllPrimesReady(() =>
         //{
         //    ri.RefTypeMeta = this.FindOrCreate(ri.RefType);
         //});
     }
 }
Пример #2
0
        private EntityPropertyMeta CreateEntityPropertyMeta(IManagedProperty mp, EntityMeta entityMeta)
        {
            var propertyType = mp.PropertyType;

            if (mp == EntityConvention.Property_Id)
            {
                propertyType = entityMeta.IdType;
            }
            else if (mp == EntityConvention.Property_TreePId)
            {
                propertyType = entityMeta.IdType;
                if (!propertyType.IsClass)
                {
                    propertyType = typeof(Nullable <>).MakeGenericType(entityMeta.IdType);
                }
            }
            var item = new EntityPropertyMeta
            {
                Owner           = entityMeta,
                Runtime         = new ManagedPropertyRuntime(mp),
                PropertyType    = propertyType,
                ManagedProperty = mp
            };

            #region 创建 ReferenceInfo 及聚合子类

            var refMP = mp as IRefEntityProperty;
            if (refMP != null)
            {
                var ri = new ReferenceInfo()
                {
                    RefEntityProperty = refMP
                };

                this.CreateReference(ri, entityMeta);

                item.ReferenceInfo = ri;
            }

            #endregion

            entityMeta.EntityProperties.Add(item);

            return(item);
        }