﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Porting MVC Music Store to Raven: Migrations</title><description>Demis,
  
Yes, it would
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment17</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment17</guid><pubDate>Tue, 25 May 2010 16:05:24 GMT</pubDate></item><item><title>Demis Bellot commented on Porting MVC Music Store to Raven: Migrations</title><description>@Ayende
  
  
Wouldn't ".Take(32).Skip(64).ToArray().Take(32)" also provide the desired result? Although it looks like in this case the last Take is redundant as the Array will only have 32 items to begin with.
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment16</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment16</guid><pubDate>Tue, 25 May 2010 13:30:46 GMT</pubDate></item><item><title>Ayende Rahien commented on Porting MVC Music Store to Raven: Migrations</title><description>Ryan,
  
If you want to do stuff like that, you make two queries.
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment15</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment15</guid><pubDate>Tue, 25 May 2010 11:27:53 GMT</pubDate></item><item><title>Ryan Heath commented on Porting MVC Music Store to Raven: Migrations</title><description>Skip/Take is implicit depending on an ordered set to be used useful.
  
When the set is ordered, then the order in which Skip/Take is executed will give different results, still with me?
  
  
Ok, if Skip/Take gives the same result as Take/Skip then the order of execution is *predefined* on the server; "always Skip first and then Take", right?
  
  
That in itself is very nice, a dev cannot make a mistake easily, but what if I *want* to Take first, then Skip and then Take again for some reason; ".Take(32).Skip(64).Take(32)"
  
Will the server return with 'i cannot comply'? Ayende?
  
  
// Ryan
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment14</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment14</guid><pubDate>Tue, 25 May 2010 06:41:22 GMT</pubDate></item><item><title>Demis Bellot commented on Porting MVC Music Store to Raven: Migrations</title><description>@Ryan,
  
  
Since the RavenDb is accessed over HTTP REST I imagine its working in very much the same way as that Linq2Sql does (as @Harry suggested) where the expression before '.ToArray()' is not executed right way but is instead serialized over HTTP and executed on the RavenDB server where processing a Skip/Take is not order dependent. After processing, the results are returned and de-serialized into an Album[].
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment13</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment13</guid><pubDate>Mon, 24 May 2010 22:36:31 GMT</pubDate></item><item><title>Harry Steinhilber commented on Porting MVC Music Store to Raven: Migrations</title><description>@Ryan,
  
I'm pretty sure Ayende has both Skip and Take implemented lazily. I.E. They don't actually do anything until you enumerate the result with ToArray(). So it knows at that time that it needs to do both and will skip/take appropriately.
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment12</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment12</guid><pubDate>Mon, 24 May 2010 18:23:46 GMT</pubDate></item><item><title>Ryan Heath commented on Porting MVC Music Store to Raven: Migrations</title><description>I think ICR is right.
  
The first loop always takes the first 128 doc and skip the remain (for no reason). Like it is written (take and then skip instead of skip and then take), I think it is a never ending loop; the first 128 docs will always return.
  
  
// Ryan
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment11</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment11</guid><pubDate>Mon, 24 May 2010 16:33:34 GMT</pubDate></item><item><title>Dennis commented on Porting MVC Music Store to Raven: Migrations</title><description>Where would you put this script? Atleast with SQL I can have a standalone script that know only the specific schema I have. For the concrete case of adding this extra column we are talking a total of 3 queries, after which all are updated and transactionally correct.
  
  
With the above you need an obsene amount of code to do the same thing, you need to have a depencency on your SoldAlbum, which means it cannot be anything standalone. And if you have users of the db at the same time, you cannot really be sure if your update was correct or not. Since your index is even made slightly after the actual update, you cant even know if your index is up2date or not.
  
  
Unfortunately, the more examples you are showing of Raven, the less I want to use it :(
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment10</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment10</guid><pubDate>Mon, 24 May 2010 07:46:35 GMT</pubDate></item><item><title>Ayende Rahien commented on Porting MVC Music Store to Raven: Migrations</title><description>ICR,
  
Not sure what you mean, Skip &amp; Take with Raven are instructions, not executed immediately
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment9</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment9</guid><pubDate>Sun, 23 May 2010 22:34:05 GMT</pubDate></item><item><title>Ayende Rahien commented on Porting MVC Music Store to Raven: Migrations</title><description>Demis,
  
The idea is to make the change transactional.
  
Every SaveChanges operation is transactional.
  
This is a single use code, no point to writing abstractions to it
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment8</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment8</guid><pubDate>Sun, 23 May 2010 22:33:21 GMT</pubDate></item><item><title>Demis Bellot commented on Porting MVC Music Store to Raven: Migrations</title><description>@[ICR]
  
  
Yep, that's exactly the other extension method I have called 'GetBatches()' which returns a list of batches. I use it when my code can take advantage of the separation, I think I'm just thrown out by the use of the same session here as I'm not exactly sure what's happening under the covers. At work we use a well defined TransactionScope to define our database transaction boundary so the above code would look something like:
  
  
foreach (var batch in session.Query&lt;Album&gt;().GetBatches(128)) {
  
  using (var scope = new TransactionScope()) {
  
    foreach (var album in batch) {
  
     …
  
    }
  
    scope.Complete();
  
  }
  
}
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment7</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment7</guid><pubDate>Sun, 23 May 2010 21:15:44 GMT</pubDate></item><item><title>[ICR] commented on Porting MVC Music Store to Raven: Migrations</title><description>@Demis Bellot - That would indeed make the first scenario a lot cleaner. However, the second time actions are taken per-batch (session save and clear) rather than per-item in the batch. That would be slightly more complex to capture, but still possible. For instance, the extension method could yield a batch (i.e. an IEnumerable) rather than each item in the batch.
  
  
foreach (var batch in session.Query
&lt;album.InBatchesOf(128)) {
  
    foreach (var album in batch) {
  
        …
  
    }
  
  
    session.SaveChanges();
  
    session.Clear();
  
}
&gt;</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment6</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment6</guid><pubDate>Sun, 23 May 2010 20:10:05 GMT</pubDate></item><item><title>[ICR] commented on Porting MVC Music Store to Raven: Migrations</title><description>Isn't the first Skip/Take the wrong way round?
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment5</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment5</guid><pubDate>Sun, 23 May 2010 19:58:45 GMT</pubDate></item><item><title>Demis Bellot commented on Porting MVC Music Store to Raven: Migrations</title><description>I guess everyone has a different way to write 'while(true)' (my preference), you use 'do / while' while others prefer the 'for (;;)'.
  
  
What is the whole reason for the 'Take / Skip' batching? Is it because you have a session TimeOut? 128 seems like a pretty small number since even when dealing with an RDBMS I find myself doing batches of 1000. Also why would you batch the reads? you're not dealing with them in a batch/stream i.e. your just sucking them up so I'm not seeing the benefit of batching them. 
  
  
I'm not sure if it makes a difference in Raven? but when you're batching in an RDBMS you need to order by primary key (or something similar) so you maintain consistent ordering.
  
  
The part I find curious here is that you are batching all within a single 'Session' scope? So if your session has a TimeOut it's going to timeout regardless of a Batch Size. Is your session equivalent to a transaction? e.g. what is the state of the data if the network goes out half-way through an import?
  
  
Lastly I think you're code would be even more readable if you had extension method to abstract away the batch logic, i.e. I use an extension method with a signature like:
  
IEnumerable
&lt;t InBatches
&lt;t,&gt;
(this IQueryable
&lt;t linqSource, int batchSize)
  
which lets me iterate over the albums like a normal collection while hiding the complexity of batching underneath so you could replace a lot of the above with:
  
  
foreach (var album in session.Query
&lt;album().InBatches(128))
  
{
  
}
&gt;</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment4</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment4</guid><pubDate>Sun, 23 May 2010 12:54:29 GMT</pubDate></item><item><title>Ayende Rahien commented on Porting MVC Music Store to Raven: Migrations</title><description>Ken,
  
You are correct when you state that the right way to do that is to do the fixups in the app code while reading.
  
You'll probably want to run code like this to do fixups on the entire thing, but that is not strictly necessary.
  
  
The code above is something that I needed for MVC Music Store while I was working on it and adding features that required additional data.
  
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment3</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment3</guid><pubDate>Sun, 23 May 2010 12:44:19 GMT</pubDate></item><item><title>Ken Egozi commented on Porting MVC Music Store to Raven: Migrations</title><description>In a multi-server deployment scenario, and when doing hot updates, you will still get old-style documents (without the count field)  written to the db, and you have no definitive point during which to run the migration. Also - considering a large dataset, that migration will cost you with downtime, and there goes the hot-updates.
  
  
What you can do,  is to have the *read* call check for document validity (i.e. countSold.HasValue), and compute it if it fails.
  
this way you can start deploying the new client code, then start running the migration, and have the "cleanup" code deal with the pieces that fell through the holes.
  
  
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment2</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment2</guid><pubDate>Sun, 23 May 2010 12:33:17 GMT</pubDate></item><item><title>Rafal commented on Porting MVC Music Store to Raven: Migrations</title><description>It may be simple but it doesn't look natural or easy. It might be one of these unnatural acts on source code where you try to make C# perform some data manipulation tricks and it's like teaching an elephant to climb trees.
</description><link>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment1</link><guid>http://ayende.com/4517/porting-mvc-music-store-to-raven-migrations#comment1</guid><pubDate>Sun, 23 May 2010 12:21:39 GMT</pubDate></item></channel></rss>