/// <summary> /// Returns the default key constraint name that would be used for this key. /// </summary> /// <param name="key"> The key. </param> /// <returns> The default key constraint name that would be used for this key. </returns> public static string GetDefaultName([NotNull] this IKey key) { var sharedTablePrincipalPrimaryKeyProperty = key.Properties[0].FindSharedTableRootPrimaryKeyProperty(); if (sharedTablePrincipalPrimaryKeyProperty != null) { return(sharedTablePrincipalPrimaryKeyProperty.FindContainingPrimaryKey().GetName()); } var builder = new StringBuilder(); var tableName = key.DeclaringEntityType.GetTableName(); if (key.IsPrimaryKey()) { builder .Append("PK_") .Append(tableName); } else { builder .Append("AK_") .Append(tableName) .Append("_") .AppendJoin(key.Properties.Select(p => p.GetColumnName()), "_"); } return(IdentifierHelpers.Truncate(builder.ToString(), key.DeclaringEntityType.Model.GetMaxIdentifierLength())); }
/// <summary> /// Returns the default name that would be used for this index. /// </summary> /// <param name="index"> The index. </param> /// <returns> The default name that would be used for this index. </returns> public static string GetDefaultName([NotNull] this IIndex index) { var baseName = new StringBuilder() .Append("IX_") .Append(index.DeclaringEntityType.GetTableName()) .Append("_") .AppendJoin(index.Properties.Select(p => p.GetColumnName()), "_") .ToString(); return(IdentifierHelpers.Truncate(baseName, index.DeclaringEntityType.Model.GetMaxIdentifierLength())); }
/// <summary> /// Returns the default constraint name that would be used for this foreign key. /// </summary> /// <param name="foreignKey"> The foreign key. </param> /// <returns> The default constraint name that would be used for this foreign key. </returns> public static string GetDefaultName([NotNull] this IForeignKey foreignKey) { var baseName = new StringBuilder() .Append("FK_") .Append(foreignKey.DeclaringEntityType.GetTableName()) .Append("_") .Append(foreignKey.PrincipalEntityType.GetTableName()) .Append("_") .AppendJoin(foreignKey.Properties.Select(p => p.GetColumnName()), "_") .ToString(); return(IdentifierHelpers.Truncate(baseName, foreignKey.DeclaringEntityType.Model.GetMaxIdentifierLength())); }
/// <summary> /// Returns the default column name to which the property would be mapped. /// </summary> /// <param name="property"> The property. </param> /// <returns> The default column name to which the property would be mapped. </returns> public static string GetDefaultColumnName([NotNull] this IProperty property) { var sharedTablePrincipalPrimaryKeyProperty = property.FindSharedTableRootPrimaryKeyProperty(); if (sharedTablePrincipalPrimaryKeyProperty != null) { return(sharedTablePrincipalPrimaryKeyProperty.GetColumnName()); } var entityType = property.DeclaringEntityType; StringBuilder builder = null; do { var ownership = entityType.GetForeignKeys().SingleOrDefault(fk => fk.IsOwnership); if (ownership == null) { entityType = null; } else { var ownerType = ownership.PrincipalEntityType; if (entityType.GetTableName() == ownerType.GetTableName() && entityType.GetSchema() == ownerType.GetSchema()) { if (builder == null) { builder = new StringBuilder(); } builder.Insert(0, "_"); builder.Insert(0, ownership.PrincipalToDependent.Name); entityType = ownerType; } else { entityType = null; } } }while (entityType != null); var baseName = property.Name; if (builder != null) { builder.Append(property.Name); baseName = builder.ToString(); } return(IdentifierHelpers.Truncate(baseName, property.DeclaringEntityType.Model.GetMaxIdentifierLength())); }
/// <summary> /// Returns the default table name that would be used for this entity type. /// </summary> /// <param name="entityType"> The entity type to get the table name for. </param> /// <returns> The default name of the table to which the entity type would be mapped. </returns> public static string GetDefaultTableName([NotNull] this IEntityType entityType) { var ownership = entityType.FindOwnership(); if (ownership != null && ownership.IsUnique) { return(ownership.PrincipalEntityType.GetTableName()); } return(IdentifierHelpers.Truncate( entityType.HasDefiningNavigation() ? $"{entityType.DefiningEntityType.GetTableName()}_{entityType.DefiningNavigationName}" : entityType.ShortName(), entityType.Model.GetMaxIdentifierLength())); }
public void GivenTheEquityClosePrices(Table table) { var rows = TableHelpers.ToEnumerableDictionary(table); foreach (var row in rows) { var item = new FactsetSecurityDailyResponseItem { Epoch = DateTime.Parse(row["Date"], null, DateTimeStyles.AssumeUniversal), ClosePrice = Convert.ToDecimal(row["ClosePrice"]), Figi = IdentifierHelpers.ToIsinOrFigi(row["_EquitySecurity"]), Currency = "GBP", DailyVolume = row.ValueOrNull("DailyVolume") != null?Convert.ToInt64(row.ValueOrNull("DailyVolume")) : 0 }; _ruleRunner.EquityClosePriceMock.Add(item); } }
public void GivenTheOrders(Table table) { var rows = TableHelpers.ToEnumerableDictionary(table); // expand special columns foreach (var row in rows) { if (row.ContainsKey("_Date")) { var value = row["_Date"]; row.AddIfNotExists("OrderPlacedDate", value); row.AddIfNotExists("OrderBookedDate", value); row.AddIfNotExists("OrderAmendedDate", value); row.AddIfNotExists("OrderFilledDate", value); } if (row.ContainsKey("_Volume")) { var value = row["_Volume"]; row.AddIfNotExists("OrderOrderedVolume", value); row.AddIfNotExists("OrderFilledVolume", value); } if (row.ContainsKey("_EquitySecurity")) { var value = row["_EquitySecurity"]; var identifier = IdentifierHelpers.ToIsinOrFigi(value); row.AddIfNotExists("MarketType", "STOCKEXCHANGE"); row.AddIfNotExists("OrderCurrency", "GBP"); row.AddIfNotExists("OrderType", "MARKET"); row.AddIfNotExists("InstrumentIsin", identifier); row.AddIfNotExists("InstrumentFigi", identifier); row.AddIfNotExists("MarketIdentifierCode", "XLON"); row.AddIfNotExists("InstrumentCfi", "e"); } if (row.ContainsKey("_FixedIncomeSecurity")) { var value = row["_FixedIncomeSecurity"]; row.AddIfNotExists("MarketType", "STOCKEXCHANGE"); row.AddIfNotExists("OrderCurrency", "GBP"); row.AddIfNotExists("OrderType", "MARKET"); row.AddIfNotExists("InstrumentRic", value); row.AddIfNotExists("MarketIdentifierCode", "RDFI"); row.AddIfNotExists("MarketName", "RDFI"); row.AddIfNotExists("InstrumentCfi", "d"); var identifier = IdentifierHelpers.ToIsinOrFigi(value); row.AddIfNotExists("InstrumentIsin", identifier); } } _ruleRunner.TradeCsvContent = MakeCsv(rows); // default allocations if (_ruleRunner.AllocationCsvContent == null) { var allocationRows = rows.Select(x => new Dictionary <string, string> { ["OrderId"] = x["OrderId"], ["Fund"] = "", ["Strategy"] = "", ["ClientAccountId"] = "", ["OrderFilledVolume"] = x.ValueOrNull("OrderFilledVolume") }); _ruleRunner.AllocationCsvContent = MakeCsv(allocationRows); } }