示例#1
0
        private EntityType AddEntity(Type entityType, IList<IManagedProperty> properties)
        {
            var type = new EntityType();
            type.Name = entityType.Name;
            type.FullName = entityType.FullName;
            if (entityType.BaseType != null)
            {
                type[BaseTypeFullNameProperty] = entityType.BaseType.FullName;
            }

            foreach (var property in properties)
            {
                if (property is IRefIdProperty)
                {
                    var refProperty = property as IRefProperty;

                    var reference = new Reference();
                    reference.ReferenceType = (Rafy.EntityObjectModel.ReferenceType)refProperty.ReferenceType;//两个枚举的值是相等的。
                    reference.IdProperty = property.Name;
                    reference.Nullable = refProperty.Nullable;
                    if (refProperty.RefEntityProperty != null)
                    {
                        reference.EntityProperty = refProperty.RefEntityProperty.Name;
                    }
                    reference[MPProperty] = refProperty;

                    type.References.Add(reference);
                    continue;
                }
                if (property is IRefEntityProperty) continue;

                if (property is IListProperty)
                {
                    var listProperty = property as IListProperty;
                    if (listProperty.HasManyType == HasManyType.Composition)
                    {
                        var child = new Child();
                        child.Name = listProperty.Name;
                        child.ListTypeFullName = listProperty.PropertyType.FullName;
                        child[MPProperty] = listProperty;

                        type.Children.Add(child);
                        continue;
                    }
                }

                var valueProperty = ConvertToValueProperty(property);
                type.ValueProperties.Add(valueProperty);
            }

            _result.EntityTypes.Add(type);

            return type;
        }
示例#2
0
        private bool ParseChild(CodeVariable codeVariable, string propertyName, string typeFullName)
        {
            if (typeFullName.Contains(ListProperty))
            {
                var initExp = codeVariable.InitExpression as string;
                if (!initExp.Contains(ListAsAggregationToken))
                {
                    var child = new Child
                    {
                        CodeElement = codeVariable,
                        Name = propertyName,
                        ListTypeFullName = UnwrapGenericType(typeFullName)
                    };
                    _currentType.Children.Add(child);
                    return true;
                }
            }

            return false;
        }