protected void SetupBase(string resourcePath)
        {
            loader = new EntityLoader(MockRepository.GenerateStub<IFileController>());

            database = new Database("DB1");
            table1 = new Table("Table1");
            table1.AddColumn(new Column("ID") { Datatype = "int" });
            table1.AddColumn(new Column("BasicClass2_Index") { Datatype = "int" });
            database.AddEntity(table1);

            table2 = new Table("Table2");
            table2.AddColumn(new Column("ID") { Datatype = "int" });
            table2.AddColumn(new Column("BASIC_CLASS_1_ID"));
            database.AddEntity(table2);

            tableManyToMany = new Table("Class1Class2");
            tableManyToMany.AddColumn(new Column("Class1ID") { Datatype = "int" });
            tableManyToMany.AddColumn(new Column("Class2ID") { Datatype = "int" });
            database.AddTable(tableManyToMany);

            relationship = table1.CreateRelationshipTo(table2);
            relationship.PrimaryKey.AddColumn("ID");
            relationship.ForeignKey.AddColumn("BASIC_CLASS_1_ID");

            // Call we are testing
            mappingSet = loader.GetEntities(new[] { Path.Combine("Resources", resourcePath) }, database);
        }
        private void buttonRunHBM2ModelTransform_Click(object sender, RoutedEventArgs args)
        {
            var loader = new EntityLoader(new FileController());
            var database = new Database("DB1", ArchAngel.Providers.EntityModel.Controller.DatabaseLayer.DatabaseTypes.SQLServer2005);
            var table = new Table("TableName", "");
            table.AddColumn(new Column("ID"));
            table.AddColumn(new Column("Speed"));
            table.AddColumn(new Column("Name"));
            table.AddColumn(new Column("Speed"));
            table.AddColumn(new Column("Discriminator"));
            table.AddColumn(new Column("Car_Make"));
            table.AddColumn(new Column("Bike_Model"));

            database.AddTable(table);
            loader.GetEntities(new[] {"nhtest.xml"}, database);
        }
        public void SetUp()
        {
            loader = new EntityLoader(MockRepository.GenerateStub<IFileController>());

            database = new Database("DB1");
            table = new Table("Transport");
            table.AddColumn(new Column("ID") { Datatype = "int" });
            table.AddColumn(new Column("Discriminator") { Datatype = "char", Size = 1});
            table.AddColumn(new Column("Name") { Datatype = "varchar", Size = 100 });
            table.AddColumn(new Column("Bike_Code") { Datatype = "varchar", Size = 5 });
            database.AddEntity(table);

            // Call we are testing
            mappingSet = loader.GetEntities(new[] { Path.Combine("Resources", "TablePerClassHierarchy.hbm.xml") }, database);
        }
        public void Setup()
        {
            loader = new EntityLoader(MockRepository.GenerateStub<IFileController>());

            database = new Database("DB1");
            table = new Table("Table1");
            table.AddColumn(new Column("ID") { Datatype = "int" });
            table.AddColumn(new Column("Column1"));
            table.AddColumn(new Column("Column2"));
            database.AddEntity(table);

            // Call we are testing
            mappingSet = loader.GetEntities(new[] { path }, database);
        }
        public LoadResult LoadEntityModelFromCSProj(string csprojFilePath, NHConfigFile nhConfigFile)
        {
            _progress.SetCurrentState("Loading Entities From Visual Studio Project", ProgressState.Normal);

            EntityLoader entityLoader = new EntityLoader(new FileController());

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(fileController.ReadAllText(csprojFilePath));
            CSProjFile csProjFile = new CSProjFile(doc, csprojFilePath);
            var hbmFiles = GetHBMFilesFromCSProj(csProjFile);

            if (IsFluentProject(csProjFile))
            {
                ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("UseFluentNHibernate", true);
                string tempFluentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Visual NHibernate" + Path.DirectorySeparatorChar + "Temp" + Path.DirectorySeparatorChar + "FluentTemp");
                var fluentHbmFiles = GetHBMFilesForFluentFromCSProj(csProjFile, tempFluentPath);
                // Combine the actual HBM files with the ones derived from FluentNH
                hbmFiles = hbmFiles.Union(fluentHbmFiles);
            }
            else
                ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("UseFluentNHibernate", false);

            var csFiles = GetCSharpFilesFromCSProj(doc, csprojFilePath);
            var nhvFiles = GetNHVFilesFromCSProj(doc, csprojFilePath);

            //NHConfigFile nhConfigFile = GetNhConfigFile(csProjFile, fileController);

            var databaseConnector = nhConfigFile == null ? null : nhConfigFile.DatabaseConnector;

            //////// GFH
            // We need to fetch ALL tables, because HBM mappings don't include association tables, or at least it's difficult to find them.
            List<SchemaData> tablesToFetch = null;// entityLoader.GetTablesFromHbmFiles(hbmFiles);

            IDatabaseLoader loader = null;
            IDatabase database = null;

            if (databaseConnector != null)
                database = GetDatabase(databaseConnector, out loader, tablesToFetch);

            _progress.SetCurrentState("Parsing your existing Model Project", ProgressState.Normal);
            var parseResults = ParseResults.ParseCSharpFiles(csFiles);

            _progress.SetCurrentState("Loading Mapping Information From NHibernate Mapping Files", ProgressState.Normal);
            var mappingSet = entityLoader.GetEntities(hbmFiles, parseResults, database);
            entityLoader.ApplyConstraints(mappingSet, nhvFiles, parseResults);

            #region Create References

            // Get a set of all Guids for tables that we will want to create references from
            HashSet<Guid> existingTables = new HashSet<Guid>(database.Tables.Select(t => t.InternalIdentifier));

            foreach (var mappedTable in mappingSet.Mappings.Select(m => m.FromTable))
                existingTables.Add(mappedTable.InternalIdentifier);

            HashSet<Guid> processedRelationships = new HashSet<Guid>();
            foreach (var table in database.Tables)
            {
                foreach (var directedRel in table.DirectedRelationships)
                {
                    var relationship = directedRel.Relationship;

                    if (processedRelationships.Contains(relationship.InternalIdentifier))
                        continue; // Skip relationships that have already been handled.
                    if (relationship.MappedReferences().Any())
                        continue; // Skip relationships that have been mapped by the user.
                    if (existingTables.Contains(directedRel.ToTable.InternalIdentifier) == false)
                        continue; // Skip relationships that have tables that have no mapped Entity

                    if (relationship.PrimaryTable.MappedEntities().FirstOrDefault() == null ||
                        relationship.ForeignTable.MappedEntities().FirstOrDefault() == null)
                    {
                        continue;
                    }
                    ArchAngel.Providers.EntityModel.Controller.MappingLayer.MappingProcessor.ProcessRelationshipInternal(mappingSet, relationship, new ArchAngel.Providers.EntityModel.Controller.MappingLayer.OneToOneEntityProcessor());
                    processedRelationships.Add(relationship.InternalIdentifier);
                }
            }
            #endregion

            foreach (var entity in mappingSet.EntitySet.Entities)
                foreach (var reference in entity.References)
                    if (!mappingSet.EntitySet.References.Contains(reference))
                        mappingSet.EntitySet.AddReference(reference);

            LoadResult result = new LoadResult();
            result.MappingSet = mappingSet;
            result.DatabaseLoader = loader;
            result.NhConfigFile = nhConfigFile;
            result.CsProjFile = csProjFile;
            return result;
        }