Porting MVC Music Store to RavenData migration
Here is the code required to take the data in the MVC Music Store database and turn into the appropriate Raven documents:
using (var documentStore = new DocumentStore { Url = "http://localhost:8080" }) { documentStore.Initialise(); using (var session = documentStore.OpenSession()) { foreach (var album in storeDB.Albums.Include("Artist").Include("Genre")) { session.Store(new { Id = "albums/" + album.AlbumId, album.AlbumArtUrl, Arist = new { album.Artist.Name, Id = "artists/" + album.Artist.ArtistId }, Genre = new { album.Genre.Name, Id = "genres/" + album.Genre.GenreId }, album.Price, album.Title, }); } foreach (var genre in storeDB.Genres) { session.Store(new { genre.Description, genre.Name, Id = "genres/" + genre.GenreId }); } session.SaveChanges(); } }
As you can see, it is pretty simple and, even if I say so myself, pretty slick.
I use anonymous types here because I am only concerned with porting the data, I don’t really care about how to deal types right now.
More posts in "Porting MVC Music Store to Raven" series:
- (31 May 2010) StoreManagerController, part 2
- (29 May 2010) StoreManagerController
- (28 May 2010) Porting the checkout process
- (25 May 2010) StoreController
- (24 May 2010) Advanced Migrations
- (23 May 2010) Migrations
- (22 May 2010) Porting the HomeController, the Right Way
- (21 May 2010) Porting the HomeController, the map/reduce way
- (20 May 2010) Data migration
- (19 May 2010) Setting up the application
- (18 May 2010) The data model

Comments
Comment preview