public void GetTableName_returns_current_TableName() { var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); Assert.Equal(null, entityTypeConfiguration.GetTableName()); entityTypeConfiguration.ToTable("Foo"); Assert.Equal("Foo", entityTypeConfiguration.GetTableName().Name); }
public void Can_get_and_set_table_name() { var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.ToTable("Foo"); Assert.Equal("Foo", entityTypeConfiguration.GetTableName().Name); }
private static bool IsNonTableSplittingForeignKey( AssociationType association, EdmProperty property) { if (association.Constraint == null || !association.Constraint.ToProperties.Contains(property)) { return(false); } EntityTypeConfiguration configuration1 = (EntityTypeConfiguration)association.SourceEnd.GetEntityType().GetConfiguration(); EntityTypeConfiguration configuration2 = (EntityTypeConfiguration)association.TargetEnd.GetEntityType().GetConfiguration(); if (configuration1 != null && configuration2 != null && (configuration1.GetTableName() != null && configuration2.GetTableName() != null)) { return(!configuration1.GetTableName().Equals(configuration2.GetTableName())); } return(true); }
public void Apply_should_set_table_name() { var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); new TableAttributeConvention() .Apply(new MockType(), entityTypeConfiguration, new TableAttribute("Foo")); Assert.Equal("Foo", entityTypeConfiguration.GetTableName().Name); }
public void ToTable_overwrites_existing_name() { var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.ToTable("Foo"); entityTypeConfiguration.ToTable("Bar"); Assert.Equal("Bar", entityTypeConfiguration.GetTableName().Name); }
public void Apply_should_not_set_table_name_when_already_set() { var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.ToTable("Bar"); new TableAttributeConvention() .Apply( new ConventionTypeConfiguration(new MockType(), () => entityTypeConfiguration, new ModelConfiguration()), new TableAttribute("Foo")); Assert.Equal("Bar", entityTypeConfiguration.GetTableName().Name); }
public void Apply_should_set_schema_name() { var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); new TableAttributeConvention() .Apply( new ConventionTypeConfiguration(new MockType(), () => entityTypeConfiguration, new ModelConfiguration()), new TableAttribute("Foo") { Schema = "Bar" }); Assert.Equal("Bar", entityTypeConfiguration.GetTableName().Schema); }
public Executable AddTask <T>(EntityTypeConfiguration <T> map, ConnectionManager manager) where T : class { FileInfo fileInfo = new FileInfo(manager.ConnectionString); string fileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - 4); string dataFlowName = $"Data Flow from {fileName} to {map.GetTableName()} in the {map.GetSchemaName()} Schema"; string dataFlowDescription = $"This data flow task will transfer the records from {manager.ConnectionString} to the {map.GetFullTableName()}"; Executable executable = CensusPackageExecutables.Contains(dataFlowName) ? CensusPackageExecutables[dataFlowName] : CensusPackageExecutables.Add("STOCK:PipelineTask"); TaskHost task = executable as TaskHost; if (task == null) { throw new ArgumentException("Failed to retrieve executable as TaskHost!"); } task.Name = dataFlowName; task.Description = dataFlowDescription; MainPipe dataFlow = task.InnerObject as MainPipe; if (dataFlow == null) { throw new ArgumentException("Unable to retrieve task as a MainPipe!"); } dataFlow.ComponentMetaDataCollection.RemoveAll(); dataFlow.Events = DtsConvert.GetExtendedInterface(new SSISComponentEventHandler()); #region Source IDTSComponentMetaData100 source = dataFlow.ComponentMetaDataCollection.New(); source.Name = $"{FlatFileSourceComponentInfo.Name} reference to {fileName}"; source.Description = $"This component will read all of the records located in {fileInfo.FullName}"; source.ContactInfo = "Anthony Hart | [email protected]"; source.ComponentClassID = FlatFileSourceComponentInfo.CreationName; CManagedComponentWrapper sourceWrapper = source.Instantiate(); sourceWrapper.ProvideComponentProperties(); source.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(manager); source.RuntimeConnectionCollection[0].ConnectionManagerID = manager.ID; source.RuntimeConnectionCollection[0].Name = "FlatFileConnection"; source.RuntimeConnectionCollection[0].Description = manager.Description; sourceWrapper.SetComponentProperty("RetainNulls", true); sourceWrapper.AcquireConnections(null); sourceWrapper.ReinitializeMetaData(); sourceWrapper.ReleaseConnections(); #endregion Source #region Destination IDTSComponentMetaData100 destination = dataFlow.ComponentMetaDataCollection.New(); destination.Name = $"{ADONETDestinationComponentInfo.Name} reference to {map.GetTableName()} in the {map.GetSchemaName()} Schema"; destination.Description = $"This component will import all of the records that were read from the {FlatFileSourceComponentInfo.Name} component into the {map.GetFullTableName()} table"; destination.ContactInfo = "Anthony Hart | [email protected]"; destination.ComponentClassID = ADONETDestinationComponentInfo.CreationName; CManagedComponentWrapper destinationWrapper = destination.Instantiate(); destinationWrapper.ProvideComponentProperties(); destination.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(DefaultConnection); destination.RuntimeConnectionCollection[0].ConnectionManagerID = DefaultConnection.ID; destination.RuntimeConnectionCollection[0].Name = "IDbConnection"; destination.RuntimeConnectionCollection[0].Description = DefaultConnection.Description; destinationWrapper.SetComponentProperty("CommandTimeout", 600); destinationWrapper.SetComponentProperty("TableOrViewName", map.GetFullTableName()); destinationWrapper.AcquireConnections(null); destinationWrapper.ReinitializeMetaData(); destinationWrapper.ReleaseConnections(); #endregion Destination #region Pathing IDTSPath100 path = dataFlow.PathCollection.New(); path.AttachPathAndPropagateNotifications(source.OutputCollection[0], destination.InputCollection[0]); #endregion #region Column Mapping IDTSInput100 input = destination.InputCollection[0]; IDTSVirtualInput100 virtualInput = input.GetVirtualInput(); foreach (IDTSVirtualInputColumn100 vColumn in virtualInput.VirtualInputColumnCollection) { IDTSInputColumn100 vCol = destinationWrapper.SetUsageType(input.ID, virtualInput, vColumn.LineageID, vColumn.Name == "TERMINATOR" ? DTSUsageType.UT_IGNORED : DTSUsageType.UT_READWRITE); if (vCol != null) { destinationWrapper.MapInputColumn(input.ID, vCol.ID, input.ExternalMetadataColumnCollection[vCol.Name].ID); } } #endregion Column Mapping return(executable); }
private static List <EntityTypeMapping> FindAllTypeMappingsUsingTable( DbDatabaseMapping databaseMapping, EntityType toTable) { List <EntityTypeMapping> entityTypeMappingList = new List <EntityTypeMapping>(); IList <EntityContainerMapping> containerMappings = databaseMapping.EntityContainerMappings; for (int index1 = 0; index1 < containerMappings.Count; ++index1) { List <EntitySetMapping> list = containerMappings[index1].EntitySetMappings.ToList <EntitySetMapping>(); for (int index2 = 0; index2 < list.Count; ++index2) { ReadOnlyCollection <EntityTypeMapping> entityTypeMappings = list[index2].EntityTypeMappings; for (int index3 = 0; index3 < entityTypeMappings.Count; ++index3) { EntityTypeMapping entityTypeMapping = entityTypeMappings[index3]; EntityTypeConfiguration configuration = entityTypeMapping.EntityType.GetConfiguration() as EntityTypeConfiguration; for (int index4 = 0; index4 < entityTypeMapping.MappingFragments.Count; ++index4) { bool flag = configuration != null && configuration.IsTableNameConfigured; if (!flag && entityTypeMapping.MappingFragments[index4].Table == toTable || flag && EntityMappingConfiguration.IsTableNameEqual(toTable, configuration.GetTableName())) { entityTypeMappingList.Add(entityTypeMapping); break; } } } } } return(entityTypeMappingList); }
public static string GetFullTableName <T>(this EntityTypeConfiguration <T> map) where T : class { return($"{map.GetSchemaName()}.{map.GetTableName()}"); }