public static void Setup(Type type) { try { var items = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(type.IsAssignableFrom).Select(t => t.Assembly); var fluentConfig = FluentMappingConfiguration.Scan(s => { foreach (var item in items) { s.Assembly(item); s.WithSmartConventions(); s.TablesNamed( t => t.GetCustomAttributes(true).OfType <TableNameAttribute>().FirstOrDefault()?.Value ?? Inflector.AddUnderscores(Inflector.MakePlural(t.Name)).ToLower()); s.Columns.Named(m => Inflector.AddUnderscores(m.Name).ToLower()); s.Columns.IgnoreWhere(x => x.GetCustomAttributes <IgnoreAttribute>().Any()); s.PrimaryKeysNamed(t => Inflector.AddUnderscores(t.Name).ToLower() + "_id"); s.PrimaryKeysAutoIncremented(t => true); } }); Config = fluentConfig; } catch (ReflectionTypeLoadException) { //Swallow } }
public static TokenInfo Create(ApiKeyContext apiKeyContext, IList <TokenInfoEducationOrganizationData> tokenInfoData) { var dataGroupedByEdOrgId = tokenInfoData .GroupBy( x => (x.EducationOrganizationId, x.NameOfInstitution, x.Discriminator), x => { string type = x.AncestorDiscriminator.Split('.')[1]; string idPropertyName = Inflector.AddUnderscores($"{type}Id"); return(new { PropertyName = idPropertyName, EducationOrganizationId = x.AncestorEducationOrganizationId }); }); var tokenInfoEducationOrganizations = new List <OrderedDictionary>(); foreach (var grouping in dataGroupedByEdOrgId) { var entry = new OrderedDictionary(); var(educationOrganizationId, nameOfInstitution, discriminator) = grouping.Key; // Add properties for current claim value entry["education_organization_id"] = educationOrganizationId; entry["name_of_institution"] = nameOfInstitution; entry["type"] = discriminator; // Add related ancestor EducationOrganizationIds foreach (var ancestorEducationOrganization in grouping) { entry[ancestorEducationOrganization.PropertyName] = ancestorEducationOrganization.EducationOrganizationId; } tokenInfoEducationOrganizations.Add(entry); } return(new TokenInfo { Active = true, ApiKey = apiKeyContext.ApiKey, NamespacePrefixes = apiKeyContext.NamespacePrefixes.ToArray(), AssignedProfiles = apiKeyContext.Profiles.ToArray(), StudentIdentificationSystem = apiKeyContext.StudentIdentificationSystemDescriptor, EducationOrganizations = tokenInfoEducationOrganizations.ToArray() }); }
public static ColumnInfo FromMemberInfo(MemberInfo mi) { var ci = new ColumnInfo { MemberInfo = mi }; var attrs = ReflectionUtils.GetCustomAttributes(mi); var colAttrs = attrs.OfType <ColumnAttribute>(); var columnTypeAttrs = attrs.OfType <ColumnTypeAttribute>(); var ignoreAttrs = attrs.OfType <IgnoreAttribute>(); var complexMapping = attrs.OfType <ComplexMappingAttribute>(); var serializedColumnAttributes = attrs.OfType <SerializedColumnAttribute>(); var reference = attrs.OfType <ReferenceAttribute>(); var aliasColumn = attrs.OfType <AliasAttribute>().FirstOrDefault(); // Check if declaring poco has [ExplicitColumns] attribute bool explicitColumns = mi.DeclaringType.GetTypeInfo().GetCustomAttributes(typeof(ExplicitColumnsAttribute), true).Any(); // Ignore column if declarying poco has [ExplicitColumns] attribute // and property doesn't have an explicit [Column] attribute, // or property has an [Ignore] attribute if ((explicitColumns && !colAttrs.Any()) || ignoreAttrs.Any()) { ci.IgnoreColumn = true; } if (complexMapping.Any()) { ci.ComplexMapping = true; ci.ComplexPrefix = complexMapping.First().CustomPrefix; } else if (serializedColumnAttributes.Any()) { ci.SerializedColumn = true; } else if (reference.Any()) { ci.ReferenceType = reference.First().ReferenceType; ci.ReferenceMemberName = reference.First().ReferenceMemberName ?? "Id"; ci.ColumnName = reference.First().ColumnName ?? mi.Name + "Id"; return(ci); } else if (PocoDataBuilder.IsList(mi)) { ci.ReferenceType = ReferenceType.Many; return(ci); } else if (mi.GetMemberInfoType().IsAClass() && !colAttrs.Any()) { ci.ComplexMapping = true; } // Read attribute if (colAttrs.Any()) { var colattr = colAttrs.First(); ci.ColumnName = colattr.Name ?? mi.Name; ci.ForceToUtc = colattr.ForceToUtc; ci.ResultColumn = colattr is ResultColumnAttribute; ci.VersionColumn = colattr is VersionColumnAttribute; ci.VersionColumnType = ci.VersionColumn ? ((VersionColumnAttribute)colattr).VersionColumnType : ci.VersionColumnType; ci.ComputedColumn = colattr is ComputedColumnAttribute; ci.ComputedColumnType = ci.ComputedColumn ? ((ComputedColumnAttribute)colattr).ComputedColumnType : ComputedColumnType.Always; } else { //Todo:The following changes were done to NPoco #region "Changes" //ci.ColumnName = mi.Name; ci.ColumnName = Inflector.AddUnderscores(mi.Name); #endregion } ci.ColumnAlias = aliasColumn != null ? aliasColumn.Alias : null; if (columnTypeAttrs.Any()) { ci.ColumnType = columnTypeAttrs.First().Type; } return(ci); }