Пример #1
0
        public void SetUp()
        {
            entities = new EntitySetImpl();

            personEntity = new EntityImpl("Person");
            personEntity.AddProperty(new PropertyImpl("ID")
            {
                Type = "int", IsKeyProperty = true
            });
            personEntity.AddProperty(new PropertyImpl("Name")
            {
                Type = "string", ValidationOptions = new ValidationOptions {
                    MaximumLength = 50
                }
            });
            personEntity.AddProperty(new PropertyImpl("Salary")
            {
                Type = "int"
            });

            managerEntity        = new EntityImpl("Manager");
            managerEntity.Parent = personEntity;

            entities.AddEntity(personEntity);
            entities.AddEntity(managerEntity);

            reference              = managerEntity.CreateReferenceTo(personEntity);
            reference.End1Enabled  = true; reference.End2Enabled = true;
            reference.End1Name     = "Subordinates"; reference.End2Name = "Manager";
            reference.Cardinality1 = Cardinality.Many; reference.Cardinality2 = Cardinality.One;
        }
Пример #2
0
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entityParent = new EntityImpl("EntityParent");
            entityParent.AddProperty(new PropertyImpl("PrimaryKey")
            {
                Type = "int", IsKeyProperty = true
            });

            entityChild = new EntityImpl("EntityChild");
            entityParent.AddChild(entityChild);
            entityChild.CopyPropertyFromParent(entityParent.ConcreteProperties[0]);
            entityChild.AddProperty(new PropertyImpl("ActualProperty")
            {
                Type = "string"
            });

            entities.AddEntity(entityParent);
            entities.AddEntity(entityChild);

            var proc = new MappingProcessor(new OneToOneEntityProcessor());

            mappingSet = proc.CreateOneToOneMapping(entities);
        }
Пример #3
0
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entity1 = new EntityImpl("Entity1");
            entity1.AddProperty(new PropertyImpl("PrimaryKey")
            {
                Type = "System.Int32", IsKeyProperty = true
            });

            entity2 = new EntityImpl("Entity2");
            entity2.AddProperty(new PropertyImpl("PrimaryKey")
            {
                Type = "System.Int32", IsKeyProperty = true
            });

            entities.AddEntity(entity1);
            entities.AddEntity(entity2);

            reference = entity1.CreateReferenceTo(entity2);
            reference.Cardinality1 = Cardinality.Many;
            reference.Cardinality2 = Cardinality.Many;

            var proc = new MappingProcessor(new OneToOneEntityProcessor());

            mappingSet = proc.CreateOneToOneMapping(entities);
        }
Пример #4
0
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entity1 = new EntityImpl("Entity1");
            entity1.AddProperty(new PropertyImpl("PrimaryKey")
            {
                Type = "System.Int32", IsKeyProperty = true
            });
            entity1.AddProperty(new PropertyImpl("Property")
            {
                Type = "bool"
            });

            entity2 = new EntityImpl("Entity2");
            entity2.AddProperty(new PropertyImpl("PrimaryKey")
            {
                Type = "System.Int32", IsKeyProperty = true
            });

            entities.AddEntity(entity1);
            entities.AddEntity(entity2);

            reference = entity1.CreateReferenceTo(entity2);
            reference.Cardinality1 = Cardinality.One;
            reference.Cardinality2 = Cardinality.One;
        }
Пример #5
0
        public void SetUp()
        {
            entity1 = new EntityImpl("Entity1");
            entity2 = new EntityImpl("Entity2");

            entitySet = new EntitySetImpl();
            entitySet.AddEntity(entity1);
            entitySet.AddEntity(entity2);
        }
Пример #6
0
        public void SetUp()
        {
            entity1 = new EntityImpl("Entity1");
            entity2 = new EntityImpl("Entity2");

            entitySet = new EntitySetImpl();
            entitySet.AddEntity(entity1);
            entitySet.AddEntity(entity2);
        }
        public void SetUp()
        {
            entity1 = new EntityImpl("Entity1");
            entity2 = new EntityImpl("Entity2");

            entitySet = new EntitySetImpl();
            entitySet.AddEntity(entity1);
            entitySet.AddEntity(entity2);

            entity1.CreateReferenceTo(entity2);
        }
Пример #8
0
        public void SetUp()
        {
            entity1 = new EntityImpl("Entity1");
            entity2 = new EntityImpl("Entity2");

            entitySet = new EntitySetImpl();
            entitySet.AddEntity(entity1);
            entitySet.AddEntity(entity2);

            entity1.CreateReferenceTo(entity2);
        }
Пример #9
0
        private static Entity CreateEntity(EntitySet set, string entityName)
        {
            var entity = new EntityImpl(entityName);
            entity.AddProperty(new PropertyImpl("Property1"));
            entity.AddProperty(new PropertyImpl("Property2"));
            entity.AddProperty(new PropertyImpl("Property3"));

            set.AddEntity(entity);

            return entity;
        }
Пример #10
0
        private static Entity CreateEntity(EntitySet set, string entityName)
        {
            var entity = new EntityImpl(entityName);

            entity.AddProperty(new PropertyImpl("Property1"));
            entity.AddProperty(new PropertyImpl("Property2"));
            entity.AddProperty(new PropertyImpl("Property3"));

            set.AddEntity(entity);

            return(entity);
        }
        public void Setup()
        {
            // Setup Database
            database = new Database("DB1");
            var table = new Table("User");

            table.AddColumn(new Column("Name"));
            table.AddColumn(new Column("AddressStreet"));
            table.AddColumn(new Column("AddressCity"));
            table.AddColumn(new Column("AddressCountry"));
            database.AddTable(table);

            // Setup Entities
            entitySet = new EntitySetImpl();
            Entity userEntity = new EntityImpl("User");

            userEntity.AddProperty(new PropertyImpl("Name"));

            // Create the Address type
            spec = new ComponentSpecificationImpl("Address");

            spec.AddProperty(new ComponentPropertyImpl("Street"));
            spec.AddProperty(new ComponentPropertyImpl("City"));
            spec.AddProperty(new ComponentPropertyImpl("Country"));

            // Create the Address component for the User entity.
            component = spec.CreateImplementedComponentFor(userEntity, "HomeAddress");

            entitySet.AddEntity(userEntity);
            entitySet.AddComponentSpecification(spec);

            // Setup the Mappings
            mappingSet       = new MappingSetImpl(database, entitySet);
            componentMapping = new ComponentMappingImpl();
            mappingSet.AddMapping(componentMapping);

            componentMapping.AddPropertyAndColumn(component.Properties[0], table.Columns[1]);
            componentMapping.AddPropertyAndColumn(component.Properties[1], table.Columns[2]);
            componentMapping.AddPropertyAndColumn(component.Properties[2], table.Columns[3]);

            // Add the mapping between the Name property and the Name column in the database table.
            mappingSet.ChangeMappedColumnFor(userEntity.ConcreteProperties[0]).To(table.Columns[0]);
        }
        public void Setup()
        {
            database  = new Database("Db1");
            entitySet = new EntitySetImpl();

            table = new Table("Table1");
            table.AddColumn(new Column("AddressStreet"));

            var entity1 = new EntityImpl("Entity1");

            componentSpec = new ComponentSpecificationImpl("Address");
            entitySet.AddComponentSpecification(componentSpec);
            componentSpec.AddProperty(new ComponentPropertyImpl("Street"));

            component1 = componentSpec.CreateImplementedComponentFor(entity1, "HomeAddress");
            component2 = componentSpec.CreateImplementedComponentFor(entity1, "WorkAddress");

            database.AddTable(table);
            entitySet.AddEntity(entity1);
        }
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entity1 = new EntityImpl("Entity1");
            entity1.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true });

            entity2 = new EntityImpl("Entity2");
            entity2.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true });

            entities.AddEntity(entity1);
            entities.AddEntity(entity2);

            reference = entity1.CreateReferenceTo(entity2);
            reference.Cardinality1 = Cardinality.Many;
            reference.Cardinality2 = Cardinality.Many;

            var proc = new MappingProcessor(new OneToOneEntityProcessor());
            mappingSet = proc.CreateOneToOneMapping(entities);
        }
Пример #14
0
        public void Setup()
        {
            // Setup Database
            database = new Database("DB1");
            var table = new Table("User");
            table.AddColumn(new Column("Name"));
            table.AddColumn(new Column("AddressStreet"));
            table.AddColumn(new Column("AddressCity"));
            table.AddColumn(new Column("AddressCountry"));
            database.AddTable(table);

            // Setup Entities
            entitySet = new EntitySetImpl();
            Entity userEntity = new EntityImpl("User");
            userEntity.AddProperty(new PropertyImpl("Name"));

            // Create the Address type
            spec = new ComponentSpecificationImpl("Address");

            spec.AddProperty(new ComponentPropertyImpl("Street"));
            spec.AddProperty(new ComponentPropertyImpl("City"));
            spec.AddProperty(new ComponentPropertyImpl("Country"));

            // Create the Address component for the User entity.
            component = spec.CreateImplementedComponentFor(userEntity, "HomeAddress");

            entitySet.AddEntity(userEntity);
            entitySet.AddComponentSpecification(spec);

            // Setup the Mappings
            mappingSet = new MappingSetImpl(database, entitySet);
            componentMapping = new ComponentMappingImpl();
            mappingSet.AddMapping(componentMapping);

            componentMapping.AddPropertyAndColumn(component.Properties[0], table.Columns[1]);
            componentMapping.AddPropertyAndColumn(component.Properties[1], table.Columns[2]);
            componentMapping.AddPropertyAndColumn(component.Properties[2], table.Columns[3]);

            // Add the mapping between the Name property and the Name column in the database table.
            mappingSet.ChangeMappedColumnFor(userEntity.ConcreteProperties[0]).To(table.Columns[0]);
        }
Пример #15
0
        private static EntitySet LoadSheetData(string file, string sheetname, Type type)
        {
            string connstr = string.Format(TemplateImport, file);
            EntityMappings mapping = type.GetMappedFields();
            EntitySet rlt = new EntitySet();
            using (OleDbConnection cn = new OleDbConnection(connstr))
            {
                try
                {
                    using (OleDbCommand cmd = cn.CreateCommand())
                    {
                        cn.Open();
                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.CommandText = string.Format(SelectScriptTemplate, sheetname);
                        using (OleDbDataReader r = cmd.ExecuteReader())
                        {
                            int row = 0;
                            List<string> columns = new List<string>();
                            while (r.Read())
                            {
                                row++;
                                Entity o = Activator.CreateInstance(type) as Entity;
                                if (o != null)
                                {
                                    for (int i = 0; i < r.VisibleFieldCount; i++)
                                    {
                                        //string n = r.GetName(i);
                                        if (row == 1)
                                        {
                                            object colobj = r.GetValue(i);
                                            columns.Add(colobj.ToString());
                                        }
                                        else
                                        {
                                            string n = columns[i];
                                            if (!string.IsNullOrEmpty(n))
                                            {
                                                n = n.Replace("/", "");
                                                n = n.Replace("\\", "");
                                                if (mapping.ContainsKey(n))
                                                {
                                                    EntityMappingsItem item = mapping[n];
                                                    FieldInfo info = item.FieldInfo;
                                                    object value = r.GetValue(i);
                                                    o.OriginalValues[n] = value;
                                                    //info.SetValue(o, value);
                                                }
                                            }
                                        }
                                    }
                                    if (row > 1)
                                    {
                                        if (!o.IsPFieldEmpty)
                                        {
                                            o._MiscInfo = string.Format("File: {0}, Sheet:{1}, Line:{2}", file, sheetname, row);
                                            rlt.AddEntity(o);
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    cn.Close();
                }

            }
            return rlt;
        }
        public void SetUp()
        {
            entities = new EntitySetImpl();

            personEntity = new EntityImpl("Person");
            personEntity.AddProperty(new PropertyImpl("ID") { Type = "int", IsKeyProperty = true });
            personEntity.AddProperty(new PropertyImpl("Name") { Type = "string", ValidationOptions = new ValidationOptions {MaximumLength = 50} });
            personEntity.AddProperty(new PropertyImpl("Salary") { Type = "int" });

            managerEntity = new EntityImpl("Manager");
            managerEntity.Parent = personEntity;

            entities.AddEntity(personEntity);
            entities.AddEntity(managerEntity);

            reference = managerEntity.CreateReferenceTo(personEntity);
            reference.End1Enabled = true; reference.End2Enabled = true;
            reference.End1Name = "Subordinates"; reference.End2Name = "Manager";
            reference.Cardinality1 = Cardinality.Many; reference.Cardinality2 = Cardinality.One;
        }
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entityParent = new EntityImpl("EntityParent");
            entityParent.AddProperty(new PropertyImpl("PrimaryKey") { Type = "int", IsKeyProperty = true });

            entityChild = new EntityImpl("EntityChild");
            entityParent.AddChild(entityChild);
            entityChild.CopyPropertyFromParent(entityParent.ConcreteProperties[0]);
            entityChild.AddProperty(new PropertyImpl("ActualProperty"){ Type = "string" });

            entities.AddEntity(entityParent);
            entities.AddEntity(entityChild);

            var proc = new MappingProcessor(new OneToOneEntityProcessor());
            mappingSet = proc.CreateOneToOneMapping(entities);
        }
Пример #18
0
        private void ProcessUnionSubclasses(object parent, MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<unionsubclass> unionsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (unionsubclasses == null) return;

            @class hClass = null;
            unionsubclass parentSubClass = null;

            if (parent is @class)
                hClass = (@class)parent;
            else
                parentSubClass = (unionsubclass)parent;

            foreach (unionsubclass hSubclass in unionsubclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                childTableMapping.FromTable = database.GetTable(hSubclass.table.UnBackTick(), hSubclass.schema.UnBackTick());
                childTableMapping.ToEntity = childEntity;

                foreach (var ip in childEntity.InheritedProperties)
                {
                    PropertyImpl np = new PropertyImpl(ip);
                    np.IsHiddenByAbstractParent = true;
                    childEntity.AddProperty(np);
                    string columnName = "";
                    var props = hClass.Properties().ToList();

                    if (hClass != null)
                    {
                        property matchingProp = hClass.Properties().SingleOrDefault(p => p.name == ip.Name);

                        if (matchingProp != null)
                        {
                            if (matchingProp.column != null)
                                columnName = matchingProp.column;
                            else if (matchingProp.Columns().Count > 0)
                                columnName = matchingProp.Columns()[0].name;
                        }
                        else
                        {
                            if (hClass.Id().column1 != null)
                                columnName = hClass.Id().column1;
                            else if (hClass.Id().column != null && hClass.Id().column.Count() > 0)
                                columnName = hClass.Id().column[0].name;
                        }
                    }
                    else
                        columnName = parentSubClass.Properties().Single(p => p.name == ip.Name).column;

                    IColumn column = childTableMapping.FromTable.GetColumn(columnName.UnBackTick());

                    if (column != null)
                        childTableMapping.AddPropertyAndColumn(np, column);
                }

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                // Add the parent's key properties as hidden properties
                foreach (var keyProp in newEntity.Key.Properties)
                {
                    Property childP = childEntity.PropertiesHiddenByAbstractParent.SingleOrDefault(p => p.Name == keyProp.Name);

                    if (childP != null)
                    {
                        //childP.IsHiddenByAbstractParent = true;
                        childP.IsKeyProperty = true;
                    }
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessUnionSubclasses(hSubclass, mappingSet, database, entities, childEntity, hSubclass.unionsubclass1, results, unqualifiedNamespace);
            }
        }
Пример #19
0
        private void ProcessSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity parentEntity, IEnumerable<subclass> subclasses, string schemaName, string tableName, ParseResults parseResults, string unqualifiedNamespace)
        {
            if (subclasses == null) return;

            foreach (subclass hSubclass in subclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);

                #region Discriminator
                if (!string.IsNullOrWhiteSpace(hSubclass.discriminatorvalue))
                {
                    childEntity.DiscriminatorValue = hSubclass.discriminatorvalue;

                    //ArchAngel.Providers.EntityModel.Model.EntityLayer.Discriminator d = new Discriminator()
                    //{
                    //    AllowNull = xx,
                    //    ColumnName = hSubclass.d,
                    //    DiscriminatorType = xx,
                    //    Force = xx,
                    //    Formula = xx,
                    //    Insert = xx
                    //};
                    //throw new NotImplementedException("TODO: fixup discriminator stuff");
                    //Grouping g = new AndGrouping();
                    //IColumn column = parentEntity.Discriminator.RootGrouping.Conditions[0].Column;
                    //ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator.Equal;
                    //ExpressionValue value = new ExpressionValueImpl(hSubclass.discriminatorvalue);

                    //if (column != null && op != null && value != null)
                    //    g.AddCondition(new ConditionImpl(column, op, value));

                    //if (childEntity.Discriminator == null)
                    //    childEntity.Discriminator = new DiscriminatorImpl();

                    //childEntity.Discriminator.RootGrouping = g;
                }
                #endregion

                parentEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();

                childTableMapping.FromTable = database.GetTable(tableName, schemaName);
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, parseResults, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessSubclasses(mappingSet, database, entities, childEntity, hSubclass.subclass1, schemaName, tableName, parseResults, unqualifiedNamespace);
            }
        }
Пример #20
0
        private void ProcessJoinedSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<joinedsubclass> joinedsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (joinedsubclasses == null) return;

            ITable parentTable = null;

            if (newEntity.MappedTables().Count() > 0)
                parentTable = newEntity.MappedTables().ElementAt(0);

            foreach (joinedsubclass hSubclass in joinedsubclasses)
            {
                Entity childEntity;
                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);

                    unqualifiedNamespace = @namespace;
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                ITable subClassTable;

                if (!string.IsNullOrEmpty(hSubclass.table))
                {
                    string schema = "";

                    if (!string.IsNullOrEmpty(hSubclass.schema))
                        schema = hSubclass.schema;
                    else if (parentTable != null)
                        schema = parentTable.Schema;

                    subClassTable = database.GetTable(hSubclass.table.UnBackTick(), schema.UnBackTick());
                    subClassTable.Database = database;
                }
                else
                    subClassTable = parentTable;

                childTableMapping.FromTable = subClassTable;
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                if (hSubclass.key != null)
                {
                    string keyColumnName;

                    if (!string.IsNullOrEmpty(hSubclass.key.column1))
                        keyColumnName = hSubclass.key.column1;
                    else //if (hSubclass.key.column != null && hSubclass.key.column.Count() > 0)
                        keyColumnName = hSubclass.key.column[0].name;

                    Property keyProp = childEntity.Properties.FirstOrDefault(p => p.MappedColumn() != null && p.MappedColumn().Name == keyColumnName);

                    if (keyProp == null)
                    {
                        keyProp = CreateProperty(childEntity, childTableMapping, hSubclass.key, subClassTable);
                        SetPropertyInfoFromParsedCode(keyProp, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, childEntity.Name);
                        keyProp.IsHiddenByAbstractParent = true;
                    }
                    keyProp.IsKeyProperty = true;
                }
                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessJoinedSubclasses(mappingSet, database, entities, childEntity, hSubclass.joinedsubclass1, results, unqualifiedNamespace);
            }
        }
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entity1 = new EntityImpl("Entity1");
            entity1.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true });
            entity1.AddProperty(new PropertyImpl("Property") { Type = "bool" });

            entity2 = new EntityImpl("Entity2");
            entity2.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true });

            entities.AddEntity(entity1);
            entities.AddEntity(entity2);

            reference = entity1.CreateReferenceTo(entity2);
            reference.Cardinality1 = Cardinality.One;
            reference.Cardinality2 = Cardinality.One;
        }