Esempio n. 1
0
        private void ProcessEntity(ASTNode node)
        {
            ASTNode nameNode = node.Children[0];
            Entity  entity   = new Entity(nameNode.Value);

            for (int i = 1; i < node.Children.Count; i++)
            {
                switch (node.Children[i].Symbol.ID)
                {
                case ExpressParser.ID.VariableSubtypeDecl:
                    if (node.Children[i].Children.Count > 0)
                    {
                        ProcessSubTypes(entity, node.Children[i].Children[0]);
                    }
                    break;

                case ExpressParser.ID.VariableSupertypeDecl:
                    ProcessInheritance(entity, node.Children[i]);
                    break;

                case ExpressParser.ID.VariableWhereDecl:
                    break;

                case ExpressParser.ID.VariablePropDecl:
                    ProcessProperty(entity, node.Children[i]);
                    break;

                default:
                    break;
                }
            }
            schema.AddEntity(entity);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds the database schema from DbSets of this instance
        /// </summary>
        private void InitializeSchema()
        {
            // get entity types from dbsets
            // any dbset<T> -> collect T as entity type
            var entityTypes = GetType().GetProperties()
                              .Where(p => p.PropertyType.IsGenericType &&
                                     p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet <>))
                              .Select(p => p.PropertyType.GetGenericArguments()[0]);

            var schemaBuilder = new SchemaBuilder(entityTypes);

            schemaBuilder.Build();
            foreach (var entity in schemaBuilder.Context.Entities)
            {
                Schema.AddEntity(entity.Value);
            }
        }