/// <summary> /// Creates a BETWEEN or NOT BETWEEN statement for <paramref name="valueA" /> and <paramref name="valueB" /> /// </summary> /// <param name="valueA">The value a.</param> /// <param name="valueB">The value b.</param> /// <returns></returns> /// <exception cref="NotSupportedException">Invalid value</exception> public ConditionalEvalQuery <TPoco> Between(object valueA, object valueB) { var prefix = ""; switch (State.Operator) { case Operator.Is: prefix = "BETWEEN"; break; case Operator.Not: prefix = "NOT BETWEEN"; break; default: throw new NotSupportedException("Invalid value"); } var valAId = ContainerObject.GetNextParameterId(); var valBId = ContainerObject.GetNextParameterId(); return(new ConditionalEvalQuery <TPoco>(this .QueryQ(string.Format("{0} @m_val{1} AND @m_val{2}", prefix, valAId, valBId), new QueryParameter(string.Format("@m_val{0}", valAId), valueA), new QueryParameter(string.Format("@m_val{0}", valBId), valueB)), State)); }
/// <summary> /// Prepaires an Conditional Query /// </summary> public ConditionalEvalQuery <TPoco> QueryOperatorValue(string operators, object value) { var nextParameterId = ContainerObject.GetNextParameterId(); return(new ConditionalEvalQuery <TPoco>(this .QueryQ(string.Format("{1} @m_val{0}", nextParameterId, operators), new QueryParameter(string.Format("@m_val{0}", nextParameterId), value)), State)); }
/// <summary> /// Creates an Column Chooser object to spezify columns to select /// </summary> /// <typeparam name="TPoco">The type of the poco.</typeparam> /// <returns></returns> public ColumnChooser <TPoco> Only <TPoco>() { if (_currentIdent == null) { _currentIdent = string.Format("{0}_{1}", ContainerObject.AccessLayer.GetClassInfo(typeof(TPoco)).TableName, ContainerObject.GetNextParameterId()); } return(new ColumnChooser <TPoco>(this, new List <string>(), _currentIdent)); }
/// <summary> /// Initializes a new instance of the <see cref="UpdateQuery{TPoco}" /> class. /// </summary> /// <param name="database">The database.</param> public UpdateQuery(IQueryBuilder database) : base(database) { CurrentIdentifier = string.Format("{0}_{1}", ContainerObject.AccessLayer.GetClassInfo(typeof(TPoco)).TableName, ContainerObject.GetNextParameterId()); }
public ConditionalEvalQuery <TEntity> Entity <TEntity>(TEntity obj) { ContainerObject.Interceptors .Add(new EventPostProcessor(EventPostProcessor.EventType.Update, ContainerObject.AccessLayer)); var dbClassInfoCache = ContainerObject.AccessLayer.GetClassInfo(typeof(TEntity)); var targetAlias = ContainerObject.CreateTableAlias(dbClassInfoCache.TableName); var queryIdentifier = new QueryIdentifier() { Value = dbClassInfoCache.TableName, QueryIdType = QueryIdentifier.QueryIdTypes.Table }; switch (ContainerObject.AccessLayer.DbAccessType) { case DbAccessType.Experimental: case DbAccessType.Unknown: case DbAccessType.OleDb: case DbAccessType.Obdc: case DbAccessType.SqLite: targetAlias.Value = queryIdentifier.Value; break; } var updatePart = new UpdateTableWithQueryPart(queryIdentifier, UpdateTableWithQueryPart.ColumsOfType(dbClassInfoCache, targetAlias, queryIdentifier, ContainerObject), targetAlias); var identityInsert = DbIdentityInsertScope.Current != null; var include = dbClassInfoCache .Propertys .Select(f => f.Value) .Where(s => { if (s.InsertIgnore) { return(false); } if (identityInsert && s.PrimaryKeyAttribute != null) { return(true); } if (s.PrimaryKeyAttribute != null) { return(false); } if (s.ForginKeyAttribute != null) { return(false); } return(!s.UpdateIgnore); }); foreach (var dbPropertyInfoCach in include) { var paramName = $"@setArg{ContainerObject.GetNextParameterId()}"; updatePart.ColumnAssignments.Add(new UpdateTableWithQueryPart.ColumnAssignment() { Column = dbPropertyInfoCach.DbName, Value = paramName, QueryParameters = { new QueryParameter(paramName, dbPropertyInfoCach.Getter.Invoke(obj), dbPropertyInfoCach.PropertyType) } }); } return(new ElementProducer <TEntity>(Add(updatePart)) .Where .PrimaryKey() .Is .EqualsTo(dbClassInfoCache.PrimaryKeyProperty.Getter.Invoke(obj))); }
/// <summary> /// Sets the Interal Alias to a new Uniq value /// </summary> public void CreateNewIdentifier() { CurrentIdentifier = string.Format("{0}_{1}", Cache.TableName, ContainerObject.GetNextParameterId()); }