<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>RavenDB</title><link>http://timlabonne.com:80/ravendb</link><description>RavenDB</description><item><title>RavenDB Survival Tip #3: Handling Polymorphism</title><link>http://timlabonne.com:80/2013/08/ravendb-survival-tip-3-handling-polymorphism/</link><description>&lt;p&gt;If you want to store objects in your database that are implementations of interfaces or base classes, you can do this pretty easily by alternating Raven&amp;rsquo;s JSON serializer settings so that when Raven serializes your object, it includes a special &amp;ldquo;$type&amp;rdquo; property in the JSON that records the full type name of the object.&lt;/p&gt;
&lt;p&gt;The documentation for RavenDB actually mentions this, but there&amp;rsquo;s a little change that I do to make it a little more efficient.&amp;nbsp; The docs say to use a TypeNameHandling convention of &amp;ldquo;All&amp;rdquo; but this will emit the $type property on &lt;em&gt;every single object&lt;/em&gt;.&amp;nbsp; This is a waste of space and creates a lot of clutter.&amp;nbsp; You should instead use TypeNameHandling.Auto.&amp;nbsp; This setting will only include the $type property if the type of the property does not match the actual type of the object.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how you&amp;rsquo;d set this up (I&amp;rsquo;m assuming that you have a DocumentStore instance available).&amp;nbsp; You&amp;rsquo;d perform this setup only when initially creating the DocumentStore (once per app):&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;store.Conventions.CustomizeJsonSerializer = serializer =&amp;gt;
{
    serializer.TypeNameHandling = 
        Raven.Imports.Newtonsoft.Json.TypeNameHandling.Auto;
};
&lt;/pre&gt;</description><pubDate>Thu, 01 Aug 2013 15:00:00 GMT</pubDate><guid isPermaLink="true">http://timlabonne.com:80/2013/08/ravendb-survival-tip-3-handling-polymorphism/</guid></item><item><title>RavenDB Survival Tip #2: Simulating select count(*)</title><link>http://timlabonne.com:80/2013/07/ravendb-survival-tip-2-simulating-select-count/</link><description>&lt;p&gt;A lot of the time a user will ask for a count of some business entity on a report so they can tell how many of something is happening.&amp;nbsp; With SQL, this is a very natural process with aggregate operations:&lt;/p&gt;&lt;pre class="brush: sql;"&gt;select count(*) from Users where IsAdmin = true
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But with RavenDB, I found it difficult to wrap my mind around how you would do this with an Index.&amp;nbsp; Aggregate operations like this are implemented with map/reduce indexes.&amp;nbsp; Since the reduce step of the index needs to have the same output shape as the map, we can’t simply return a single numeric value as is the case with SELECT COUNT(*) in SQL.&amp;nbsp; We need to perform a LINQ group-by.&amp;nbsp; But in this case, I don’t really want to group by anything in a document, I just want a count.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;After a little thinking and digging around, I found a solution.&amp;nbsp; Maybe this is obvious to most, but I found that if we simply group by a constant, we can get a single numeric value for that constant the represents the total count.&lt;/p&gt;
&lt;p&gt;Here’s a sample Index definition that demonstrates this concept.&amp;nbsp; In the Index, I am trying to find all User documents that qualify as admins (IsAdmin = true).&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class Users_AdminCounts : AbstractIndexCreationTask&amp;lt;User, Users_AdminCounts.ReduceResult&amp;gt;
{
    public class ReduceResult
    {
        public string Name { get; set; }
        public int Count { get; set; }
    }

    public Users_AdminCounts()
    {
        // the Name parameter to the reduce function is dummy
        // to get it to aggregate to one single value
        Map = users =&amp;gt;
            from user in users
            where user.IsAdmin = true
            select new { Name = "Total", Count = 1 };

        Reduce = results =&amp;gt;
            from result in results
            group result by result.Name
            into g
            select new { Name = g.Key, Count = g.Sum(x =&amp;gt; x.Count) };
    }
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When you run the query and get the result (ReduceResult), you will get just one single result and the Count property will contain the count aggregate you are looking for.&lt;/p&gt;</description><pubDate>Wed, 10 Jul 2013 19:00:00 GMT</pubDate><guid isPermaLink="true">http://timlabonne.com:80/2013/07/ravendb-survival-tip-2-simulating-select-count/</guid></item><item><title>RavenDB Survival Tip #1: Indexing Gotcha</title><link>http://timlabonne.com:80/2013/04/ravendb-survival-tip-1-indexing-gotcha/</link><description>&lt;p&gt;This series of posts is going to cover some things I’ve learned using RavenDB, a document database solution for .NET.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I was working on a class (a User class) where I needed to add a property to the class that didn’t exist in the original version of the application.&amp;nbsp;&amp;nbsp; So, I went and added it to the C# class (User) and I also updated an Index in RavenDB to use this new property so that I could filter by it in a query.&amp;nbsp; It built and when I deployed I could see that Raven was updating the index and did so in a timely manner.&lt;/p&gt; &lt;p&gt;I then went and wrote some code to filter by that new property in a query.&amp;nbsp; The property I had added was a boolean type and so all of the models that I had in the database (some 50,000+ User documents) would just get the default value of false for this new property.&amp;nbsp;&amp;nbsp; However, when I went to run this query, &lt;em&gt;no&lt;/em&gt; documents were returned.&amp;nbsp; What happened was that when you add a new property to a model, it isn’t going to go and update all of your existing documents with a property value even if a default is implied or provided (as is the case with a bool being false by default).&amp;nbsp; There is simply no property in the JSON store in the User document that matches this property I was querying by.&amp;nbsp; &lt;/p&gt; &lt;p&gt;The solution is that when you do something like that, you need to run a &lt;a href="http://ravendb.net/docs/client-api/partial-document-updates" target="_blank"&gt;Patch&lt;/a&gt; in RavenDB.&amp;nbsp; This will ensure that all of your documents get synced to the new additional property you have made.&amp;nbsp; Perhaps if this was some integer or string property that had to be set to something specific I would have picked up on the problem before even attempting the query.&amp;nbsp; &lt;/p&gt;</description><pubDate>Wed, 24 Apr 2013 15:03:00 GMT</pubDate><guid isPermaLink="true">http://timlabonne.com:80/2013/04/ravendb-survival-tip-1-indexing-gotcha/</guid></item><item><title>Setting Up RavenDB as IIS Website</title><link>http://timlabonne.com:80/2013/03/setting-up-ravendb-as-iis-website/</link><description>&lt;p&gt;Over the past year, I’ve gotten to know &lt;a href="http://ravendb.net" target="_blank"&gt;RavenDB&lt;/a&gt; which is an excellent NoSQL document database product from Hibernating Rhinos.&amp;nbsp; It’s an open source project built in .NET that fits in well with .NET technologies like LINQ.&amp;nbsp; I love the process of taking my domain objects and simply dumping them into a database and being able to retrieve them with very little effort.&amp;nbsp; The programming experience is excellent.&lt;/p&gt; &lt;p&gt;But since this is new to most people (and organizations), getting started setting up a RavenDB server to connect to can be a little challenging getting everything right, especially if you don’t have the infrastructure support of IIS experts and/or DBAs.&amp;nbsp; This post shows step-by-step instructions on how to set up RavenDB on an IIS 7.x system.&amp;nbsp; These instructions have worked well for me and make the following assumptions:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;You want to use IIS to host RavenDB (you can also embed it or use Windows Services – I won’t talk about that right now).&lt;/li&gt; &lt;li&gt;You want to use HTTPS as your transport protocol.&lt;/li&gt; &lt;li&gt;You want to use integrated Windows security to authorize users to access your DB.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Here’s what you should do to achieve this (this is for version 2.0 of RavenDB, build 2261 or higher):&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Ensure you have the following software installed on your server:&lt;/li&gt; &lt;ol&gt; &lt;li&gt;IIS 7.5&lt;/li&gt; &lt;li&gt;.NET Framework 4.0 – it might not be installed if you are on Windows Server 2008 (it shipped with 3.5 SP1)&lt;/li&gt; &lt;li&gt;Get the .zip of the &lt;a href="http://builds.hibernatingrhinos.com/builds/RavenDB" target="_blank"&gt;latest stable RavenDB build&lt;/a&gt; (or an unstable build if you wish).&amp;nbsp; Unzip to a directory on the server.&amp;nbsp; The sub-directory /Web is where the web site will run from.&amp;nbsp; I put this on same disk as the Raven Data directory.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Install Windows Authentication service.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Server Manager –&amp;gt; Roles –&amp;gt; Web Server, then click on Add Role Services link.&lt;/li&gt; &lt;li&gt;Check “Windows Authentication” and then continue.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Setup proper DNS to point to your server’s IP address (this is probably already done).&lt;/li&gt; &lt;li&gt;If you are behind a corporate firewall, have them open port 8080 (or whatever port you are using).&amp;nbsp; You probably want it open to your entire subnet including a VPN IP range if you have that.&lt;/li&gt; &lt;li&gt;Obtain and install an SSL certificate for the domain for the machine.&lt;/li&gt; &lt;li&gt;Create a new application pool for the web site.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Set it to use .NET 4.0 and Integrated Pipeline.&lt;/li&gt; &lt;li&gt;Give it a name such as “RavenAppPool”&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Disable overlapped recycle on the app pool.&amp;nbsp; Raven doesn’t want multiple instances attempting to write to its files.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;On the app pool you just created –&amp;gt; Advanced Settings –&amp;gt; Disable Overlapped Recycle set to True.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Set the app pool so that IIS never shuts it down.&amp;nbsp; You want your DB up at all times.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;The setting for this can’t be applied in the GUI for IIS 7.5.&lt;/li&gt; &lt;li&gt;Find C:\Windows\System32\inetsrv\config\applicationHost.config and open it.&amp;nbsp; Make a backup copy.&lt;/li&gt; &lt;li&gt;Find the app pool entry for the app pool you created for Raven.&lt;/li&gt; &lt;li&gt;Add the attribute startMode=”AlwaysRunning” to it and save the file.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Create a new website or set Default Web Site.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Right click Sites under Web Server and choose Add New Site.&lt;/li&gt; &lt;li&gt;Set site name to “RavenDB” or whatever you want.&lt;/li&gt; &lt;li&gt;Set the app pool to the RavenAppPool you created in step 6.&lt;/li&gt; &lt;li&gt;Set the physical path to the /Web folder of the RavenDB install.&lt;/li&gt; &lt;li&gt;Set HTTP binding if not already.&lt;/li&gt; &lt;li&gt;Uncheck start web site immediately.&lt;/li&gt; &lt;li&gt;Click OK.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Create a RavenDB user group.&amp;nbsp; This is a Windows group that represents the users that can login to RavenDB.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Server Manager –&amp;gt; Configuration –&amp;gt; Local Users and Groups…&lt;/li&gt; &lt;li&gt;Right-click on Groups folder, select New Group…&lt;/li&gt; &lt;li&gt;Give group a name and description ("RavenDB”)&lt;/li&gt; &lt;li&gt;Click OK.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;If you are connecting with an application, create a new user now for the proxy account that will use this database.&amp;nbsp; This user should belong to the \RavenDB group you just created.&amp;nbsp; You should also create any DBA or developer accounts now and give them this group as well.&lt;/li&gt; &lt;li&gt;Turn on Require SSL for the website.&lt;/li&gt; &lt;li&gt;Configure where Indexes and Data directories are.&amp;nbsp; You should have two different disks for best parallel I/O – one for the Indexes and one for the Data.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Open the web.config file in the /Web folder of the RavenDB install.&lt;/li&gt; &lt;li&gt;In &amp;lt;appSettings&amp;gt;, add a setting for data path - &amp;lt;add key=”Raven/DataDir” value=”[your path here]” /&amp;gt;&lt;/li&gt; &lt;li&gt;Also add a setting for indexes - &amp;lt;add key=”Raven/IndexStoragePath” value=”[your path here]” /&amp;gt;&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Start the web site.&lt;/li&gt; &lt;li&gt;In a web browser with Silverlight plugin installed, navigate to &lt;a href="https://[yoursitedomain]:[port]/"&gt;https://[yoursitedomain]:[port]/&lt;/a&gt; to make sure the Management Studio opens.&amp;nbsp; If it works, you know that RavenDB started, created the default database and that your website is serving data correctly over HTTPS and your firewall rules are correct.&lt;/li&gt; &lt;li&gt;Turn on Windows Authentication&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Click on RavenDB web site just created.&lt;/li&gt; &lt;li&gt;Select Authentication from IIS categories.&lt;/li&gt; &lt;li&gt;Click on Windows Authentication from the list and click Enable link&amp;nbsp; on the actions panel.&lt;/li&gt; &lt;li&gt;Turn off anonymous access in Raven:&amp;nbsp; open its web.config file and add the following setting to the &amp;lt;appSettings&amp;gt; section - &amp;lt;add key=”Raven/AnonymousAccess” value=”None” /&amp;gt;&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Configure Raven to only allow that specific Windows group you created earlier.&lt;/li&gt; &lt;ol&gt; &lt;li&gt;In Raven Management studio, click on the databases link at the top right.&amp;nbsp; &lt;/li&gt; &lt;li&gt;Click on the &amp;lt;system&amp;gt; database button on the right.&amp;nbsp; It will warn you about modifying the system database, just click OK.&lt;/li&gt; &lt;li&gt;Now click the “gear” icon at the top next to the &amp;lt;system&amp;gt; database name to open the settings for the db.&lt;/li&gt; &lt;li&gt;Select Windows Authentication from the left pane.&lt;/li&gt; &lt;li&gt;On the Groups tab, click Add Group Settings.&lt;/li&gt; &lt;li&gt;In the Name text box, add the name of your windows group preceded by a slash (“\RavenDB”).&lt;/li&gt; &lt;li&gt;Check Enabled.&lt;/li&gt; &lt;li&gt;Add the specific databases to the group (such as the default database or a specific tenant you may have created).&lt;/li&gt; &lt;li&gt;Click Save Changes button to complete.&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Open Management Studio again.&amp;nbsp; You should be prompted by your browser for a username and password.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;These instructions will create you a running RavenDB instance in IIS that has HTTPS transport security, Windows security, and does not allow anonymous access.&amp;nbsp; It also configured where indexes and data are written to and made sure IIS doesn’t recycle your process or start two of them at once.&lt;/p&gt; &lt;p&gt;The official documentation can also help you out if you are having any trouble:&amp;nbsp; &lt;a href="http://ravendb.net/docs/2.0/server/deployment/as-iis-application"&gt;http://ravendb.net/docs/2.0/server/deployment/as-iis-application&lt;/a&gt;&lt;/p&gt;</description><pubDate>Thu, 07 Mar 2013 14:15:00 GMT</pubDate><guid isPermaLink="true">http://timlabonne.com:80/2013/03/setting-up-ravendb-as-iis-website/</guid></item></channel></rss>