public static IQueryable <UtilityTable> CreateTableQuery(string accountName, DbTableDataContext context) { return(new DbTableRowQueryable <UtilityTable>(new DbTableRowQueryProvider <UtilityTable>(context, accountName, "Tables"))); }
private void ProcessChange(ChangeDescription changeDescription) { TableRow sqlEntity = null; PointQueryTracker pointQuery = null; DbTableDataContext failedCommandIndex = this; failedCommandIndex.FailedCommandIndex = failedCommandIndex.FailedCommandIndex + 1; switch (changeDescription.UpdateType) { case UpdateKind.Insert: { this.CheckPermissions(null, changeDescription); this.CheckPartitionAndRowKeys(((UtilityRow)changeDescription.Row).PartitionKey, ((UtilityRow)changeDescription.Row).RowKey, changeDescription.UpdateType); DateTime?nullable = null; sqlEntity = this.GetSqlEntity(((UtilityRow)changeDescription.Row).PartitionKey, ((UtilityRow)changeDescription.Row).RowKey, nullable); if (sqlEntity != null) { throw new TableServiceGeneralException(TableServiceError.EntityAlreadyExists, null); } UtilityRow row = (UtilityRow)changeDescription.Row; this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(row.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(row.RowKey), changeDescription); this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(row)); return; } case UpdateKind.Delete: { if (changeDescription.IfMatchHeaderMissing) { throw new XStoreArgumentException("If-Match header is mandatory when deleting an entity."); } sqlEntity = this.CheckAndGetEntity(changeDescription, true); this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription); this.m_dbContext.TableRows.DeleteOnSubmit(sqlEntity); return; } case UpdateKind.Replace: { sqlEntity = this.CheckAndGetEntity(changeDescription, true); this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription); sqlEntity.Data = XmlUtility.GetXmlFromUtilityRow(changeDescription.Row as UtilityRow); return; } case UpdateKind.Merge: { sqlEntity = this.CheckAndGetEntity(changeDescription, true); this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription); sqlEntity.Data = XmlUtility.MergeXmlProperties(changeDescription.Row as UtilityRow, sqlEntity.Data); return; } case UpdateKind.InsertOrMerge: { this.ExecuteQuery <UtilityRow>(changeDescription); pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery; if (pointQuery == null) { throw new DataServiceException(400, "PK and RK not present in the required format"); } (changeDescription.Row as UtilityRow).PartitionKey = pointQuery.PartitionKey; (changeDescription.Row as UtilityRow).RowKey = pointQuery.RowKey; sqlEntity = this.CheckAndGetEntity(changeDescription, false); this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.RowKey), changeDescription); if (sqlEntity != null) { sqlEntity.Data = XmlUtility.MergeXmlProperties(changeDescription.Row as UtilityRow, sqlEntity.Data); return; } this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(changeDescription.Row as UtilityRow)); return; } case UpdateKind.InsertOrReplace: { this.ExecuteQuery <UtilityRow>(changeDescription); pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery; if (pointQuery == null) { throw new DataServiceException(400, "PK and RK not present in the required format"); } (changeDescription.Row as UtilityRow).PartitionKey = pointQuery.PartitionKey; (changeDescription.Row as UtilityRow).RowKey = pointQuery.RowKey; sqlEntity = this.CheckAndGetEntity(changeDescription, false); this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.RowKey), changeDescription); if (sqlEntity != null) { sqlEntity.Data = XmlUtility.GetXmlFromUtilityRow(changeDescription.Row as UtilityRow); return; } this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(changeDescription.Row as UtilityRow)); return; } default: { return; } } }
public static IQueryable <UtilityRow> CreateRowQuery(string accountName, string tableName, DbTableDataContext context) { DbTableRowQueryProvider <UtilityRow> dbTableRowQueryProvider = new DbTableRowQueryProvider <UtilityRow>(context, accountName, tableName); if (context.SignedAccountIdentifier != null && (context.SignedAccountIdentifier.StartingPartitionKey != null || context.SignedAccountIdentifier.StartingRowKey != null || context.SignedAccountIdentifier.EndingPartitionKey != null || context.SignedAccountIdentifier.EndingRowKey != null)) { KeyBounds keyBound = new KeyBounds() { MinPartitionKey = context.SignedAccountIdentifier.StartingPartitionKey, MinRowKey = context.SignedAccountIdentifier.StartingRowKey, MaxPartitionKey = context.SignedAccountIdentifier.EndingPartitionKey, MaxRowKey = context.SignedAccountIdentifier.EndingRowKey }; dbTableRowQueryProvider.SASKeyBounds = keyBound; } return(new DbTableRowQueryable <UtilityRow>(dbTableRowQueryProvider)); }
public DbTableRowQueryProvider(DbTableDataContext context, string accountName, string userResourceName) { this._context = context; this._accountName = accountName; this._userResourceName = userResourceName; }