예제 #1
0
        public static Action <TdsColumnWriter, T> GetComplexWriter <T>(TdsColumnWriter writer)
        {
            var newMapping = GetPreMappedColumns(writer);

            if (newMapping.Length == 0)
            {
                newMapping = GetDefaultMapping <T>(writer);
            }
            return(_GetWriter <T>(newMapping));
        }
예제 #2
0
        private static Mapping[] GetDefaultMapping <T>(TdsColumnWriter writer)
        {
            var sqlTableColumns  = GetDefaultMapping(writer.MetaData);
            var typeColumns      = typeof(T).GetPublicProperties();
            var columnsNotMapped = sqlTableColumns.Select(x => x.SqlName).Except(typeColumns.Keys).ToArray();

            if (columnsNotMapped.Any())
            {
                throw new ArgumentException($"Not all columns are mapped to class properties. The follow columns could not mapped: {string.Join(",", columnsNotMapped)}");
            }

            var newMapping = sqlTableColumns.Select(x => new Mapping {
                SqlIndex = x.SqlIndex, PropertyInfo = typeColumns[x.SqlName], SqlName = x.SqlName, TdsType = x.TdsType
            }).ToArray();

            return(newMapping);
        }
예제 #3
0
 private static Mapping[] GetPreMappedColumns(TdsColumnWriter writer)
 {
     return(writer.MetaData.Where(x => x.PropertyInfo != null).Select((x, i) => new Mapping {
         PropertyInfo = x.PropertyInfo, SqlName = x.Column, TdsType = x.TdsType, SqlIndex = i
     }).ToArray());
 }