1 public class Album : TableServiceEntity 2 { 3 } 4 public class PhotoAlbumDataContext : TableServiceContext 5 { 6 public PhotoAlbumDataContext() 7 : this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString")) 8 { 9 } 10 11 public PhotoAlbumDataContext(Microsoft.WindowsAzure.CloudStorageAccount account) 12 : base(account.TableEndpoint.ToString(), account.Credentials) 13 { 14 if (!initialized) 15 { 16 lock (initializationLock) 17 { 18 if (!initialized) 19 { 20 this.CreateTables(); 21 initialized = true; 22 } 23 } 24 } 25 26 } 27 //getlist 28 var context = new PhotoAlbumDataContext(); 29 var list=context.Albums.AsTableServiceQuery().AsEnumerable() 30 31 32 //add 33 context.AddObject("Alblum_TableName", new Album()); 34 //context.SaveChanges(); 35 context.SaveChanges(SaveChangesOptions.ContinueOnError); 36 37 38 //get delete 39 var album = context.Albums 40 .Where(a => a.AlbumId == albumName && a.PartitionKey == owner.ToLowerInvariant()).AsTableServiceQuery() 41 .Single(); 42 43 context.DeleteObject(album); 44 context.SaveChanges(); 45 46 //delete 47 context.AttachTo("TableName", photoRow, "*"); 48 context.DeleteObject(photoRow); 49 context.SaveChanges(); 50 51 52 53 //update 54 var albumRow = new Album(album); 55 // attach and update the photo row 56 context.AttachTo("TableName", albumRow, "*"); 57 context.UpdateObject(albumRow); 58 context.SaveChanges(); 59 60 61 62
相关文章: