private IOrderbyClauseBuilder <T> New(Expression <Func <T, object> > member, OrderbyType type)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            var mn   = _dialectSettings.GetEscapeName(member);
            var rule = type == OrderbyType.Ascending ? "ASC" : "DESC";

            _tuples?.Add(new KeyValuePair <string, string>(mn, rule));

            return(this);
        }
Beispiel #2
0
 public OrderbyClauseResult ConstructOrderbyClause <TKey, TEntity>(Expression <Func <TEntity, object> > member, OrderbyType orderbyType) where TKey : IEquatable <TKey> where TEntity : class, IEntity <TKey>
 {
     return((OrderbyClauseResult)$"{_dialectSettings.GetEscapeName(member)} {(orderbyType == OrderbyType.Ascending ? "ASC" : "DESC")}");
 }
Beispiel #3
0
        public CommandTextEventInfo ConstructInsertSql <TKey, TEntity>(IList <Expression <Func <TEntity, object> > > logicFields, TEntity entityToInsert, IEnumerable <Expression <Func <TEntity, object> > > ignoredFields, bool autoIncrement) where TKey : IEquatable <TKey> where TEntity : class, IEntity <TKey>
        {
            if (entityToInsert == null)
            {
                throw new ArgumentNullException(nameof(entityToInsert));
            }

            var writer     = new StringTextWriter();
            var dynParms   = new DynamicParameters();
            var entityType = typeof(TEntity);
            var tableName  = _dialectSettings.GetEscapeName(entityType);

            var tp = entityType.GetRuntimeProperties().Where(p => p.PropertyType.IsSimpleType());

            if (logicFields != null)
            {
                tp = tp.Where(p => !logicFields.Any(exp => string.Equals(p.Name, exp.GetMemberName(), StringComparison.Ordinal)));
            }
            if (ignoredFields != null)
            {
                tp = tp.Where(p => !ignoredFields.Any(exp => string.Equals(p.Name, exp.GetMemberName(), StringComparison.Ordinal)));
            }

            var properties = tp.ToList();
            var kvps       = new List <KeyValuePair <string, string> >(properties.Count);

            foreach (var property in properties)
            {
                var paramName = _dialectSettings.GetParameterName(property);
                dynParms.Add(paramName, property.GetValue(entityToInsert));
                kvps.Add(new KeyValuePair <string, string>(_dialectSettings.GetEscapeName(property), paramName));
            }

            writer.Write($"INSERT INTO {tableName} ({string.Join(", ", kvps.Select(kvp => kvp.Key))}) VALUES ({string.Join(", ", kvps.Select(kvp => kvp.Value))}) ;");
            // ReSharper disable once InvertIf
            if (autoIncrement)
            {
                writer.Write(_dialectSettings.GetIdentitySql);
                writer.Write(" ;");
            }

            return(new CommandTextEventInfo(writer.ToStringWithClear(), dynParms));
        }