예제 #1
0
        public static Row CreateRow(ICollection <KeyValuePair <string, object> > valueMap)
        {
            var columns    = new List <CqlColumn>();
            var rowValues  = new List <object>();
            var serializer = new SerializerManager(ProtocolVersion.MaxSupported).GetCurrentSerializer();

            foreach (var kv in valueMap)
            {
                if (kv.Value != null)
                {
                    IColumnInfo typeInfo;
                    var         typeCode = serializer.GetCqlType(kv.Value.GetType(), out typeInfo);
                    columns.Add(new CqlColumn {
                        Name = kv.Key, TypeCode = typeCode, TypeInfo = typeInfo
                    });
                }
                else
                {
                    columns.Add(new CqlColumn()
                    {
                        Name = kv.Key, TypeCode = ColumnTypeCode.Text
                    });
                }
                rowValues.Add(kv.Value);
            }
            var i = 0;

            return(new Row(rowValues.ToArray(), columns.ToArray(), valueMap.ToDictionary(kv => kv.Key, kv => i++)));
        }
예제 #2
0
        private static CqlColumn[] CreateColumns(ICollection <KeyValuePair <string, object> > rowValues)
        {
            var columns    = new CqlColumn[rowValues.Count];
            var index      = 0;
            var serializer = new SerializerManager(ProtocolVersion.MaxSupported).GetCurrentSerializer();

            foreach (var kv in rowValues)
            {
                CqlColumn c;
                if (kv.Value != null)
                {
                    IColumnInfo typeInfo;
                    var         typeCode = serializer.GetCqlType(kv.Value.GetType(), out typeInfo);
                    c = new CqlColumn
                    {
                        Name     = kv.Key,
                        TypeCode = typeCode,
                        TypeInfo = typeInfo,
                        Type     = kv.Value.GetType(),
                        Index    = index
                    };
                }
                else
                {
                    // Default to type Text
                    c = new CqlColumn
                    {
                        Name     = kv.Key,
                        TypeCode = ColumnTypeCode.Text,
                        Type     = typeof(string),
                        Index    = index
                    };
                }
                columns[index++] = c;
            }
            return(columns);
        }