public IManyColumnBuilder <T2> Many <T2>(Expression <Func <T, IList <T2> > > property) { var members = MemberHelper <T> .GetMembers(property); var columnDefinition = new ColumnDefinition() { MemberInfo = members.Last() }; var builder = new ManyColumnBuilder <T2>(columnDefinition); var key = PocoColumn.GenerateKey(members); _columnDefinitions[key] = columnDefinition; return(builder); }
public IColumnBuilder <T2> Column <T2>(Expression <Func <T, T2> > property) { MemberInfo[] members = MemberHelper <T> .GetMembers(property); MemberInfo memberInfo = members.Last(); ColumnDefinition columnDefinition = new ColumnDefinition() { MemberInfo = memberInfo }; ColumnBuilder <T2> builder = new ColumnBuilder <T2>(columnDefinition); string key = PocoColumn.GenerateKey(members); this._columnDefinitions[key] = columnDefinition; return(builder); }
private static Mappings CreateMappings(ConventionScannerSettings scannerSettings, Type[] typesOverride) { var types = typesOverride ?? FindTypes(scannerSettings); var config = new Dictionary <Type, TypeDefinition>(); foreach (var type in types) { var pocoDefn = new TypeDefinition(type) { AutoIncrement = scannerSettings.PrimaryKeysAutoIncremented(type), PrimaryKey = scannerSettings.PrimaryKeysNamed(type), TableName = scannerSettings.TablesNamed(type), PersistedType = scannerSettings.PersistedTypesBy(type), SequenceName = scannerSettings.SequencesNamed(type), UseOutputClause = scannerSettings.UseOutputClauseWhere(type), ExplicitColumns = true }; foreach (var columnDefinition in GetColumnDefinitions(scannerSettings, type, new List <MemberInfo>())) { var key = PocoColumn.GenerateKey(columnDefinition.MemberInfoChain); if (!pocoDefn.ColumnConfiguration.ContainsKey(key)) { pocoDefn.ColumnConfiguration.Add(key, columnDefinition); } } config.Add(type, pocoDefn); } foreach (var mappingOverride in scannerSettings.MappingOverrides) { MergeOverrides(config, mappingOverride); } //if (scannerSettings.OverrideWithAttributes) //{ // MergeAttributeOverrides(config); //} var pocoMappings = new Mappings { Config = config }; return(pocoMappings); }
internal static IEnumerable <PosName> ConvertFromNewConvention(this IEnumerable <PosName> posNames, PocoData pocoData) { var allMembers = pocoData.GetAllMembers().ToList(); var scopedPocoMembers = pocoData.Members; string prefix = null; foreach (var posName in posNames) { if (posName.Name == "npoco") { scopedPocoMembers.Clear(); prefix = null; continue; } if (posName.Name.StartsWith(SplitPrefix, StringComparison.OrdinalIgnoreCase)) { prefix = posName.Name.Substring(SplitPrefix.Length); var relevantMembers = allMembers.SingleOrDefault(x => string.Equals(PocoColumn.GenerateKey(x.MemberInfoChain), prefix, StringComparison.OrdinalIgnoreCase)); if (relevantMembers != null) { scopedPocoMembers = relevantMembers.PocoMemberChildren; } continue; } var member = FindMember(scopedPocoMembers, prefix, posName.Name); if (member != null && member.PocoColumn != null) { posName.Name = member.PocoColumn.MemberInfoKey; } else { posName.Name = PocoDataBuilder.JoinStrings(prefix, posName.Name); } yield return(posName); } }