public DeleteQuery <T> Delete <T>() { ContainerObject.Interceptors .Add(new EventPostProcessor(EventPostProcessor.EventType.Delete, ContainerObject.AccessLayer)); var dbClassInfoCache = ContainerObject.AccessLayer.GetClassInfo(typeof(T)); 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; } return(new DeleteQuery <T>( Add(new DeleteTableQueryPart(queryIdentifier, targetAlias, dbClassInfoCache, ContainerObject, UpdateTableWithQueryPart.ColumsOfType(dbClassInfoCache, targetAlias, queryIdentifier, ContainerObject))))); }
/// <summary> /// Creates a Update statement for a given type /// </summary> /// <typeparam name="TPoco">The type of the poco.</typeparam> /// <returns></returns> public UpdateColumnSetters <TPoco> Table <TPoco>() { ContainerObject.Interceptors .Add(new EventPostProcessor(EventPostProcessor.EventType.Update, ContainerObject.AccessLayer)); var dbClassInfoCache = ContainerObject.AccessLayer.GetClassInfo(typeof(TPoco)); var targetAlias = ContainerObject.CreateTableAlias(dbClassInfoCache.TableName); var queryIdentifier = new QueryIdentifier() { Value = dbClassInfoCache.TableName, QueryIdType = QueryIdentifier.QueryIdTypes.Table }; if (ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.Experimental) || ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.Unknown) || ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.OleDb) || ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.Obdc) || ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.SqLite)) { targetAlias.Value = queryIdentifier.Value; } return(new UpdateColumnSetters <TPoco>( Add(new UpdateTableWithQueryPart( queryIdentifier, UpdateTableWithQueryPart.ColumsOfType(dbClassInfoCache, targetAlias, queryIdentifier, ContainerObject), targetAlias)))); }
/// <summary> /// Selects all columns from the given Identifier /// </summary> /// <returns></returns> public SelectQuery <TPoco> Identifier <TPoco>(QueryIdentifier identifier) { ContainerObject.Interceptors.Add(new EventPostProcessor(EventPostProcessor.EventType.Select, ContainerObject.AccessLayer)); var classInfo = ContainerObject.AccessLayer.GetClassInfo(typeof(TPoco)); return(new SelectQuery <TPoco>(Add(new SelectTableQueryPart( ContainerObject.Search(identifier), classInfo, ContainerObject.CreateTableAlias(classInfo.TableName), ContainerObject)))); }
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))); }