<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marker Studio - Full Service Digital Agency &#187; repository</title>
	<atom:link href="http://www.markerstudio.com/tag/repository/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markerstudio.com</link>
	<description>Full Service Digital Agency</description>
	<lastBuildDate>Tue, 17 Jan 2012 19:05:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Introducing the Marker Kentico Business Library (MKB)</title>
		<link>http://www.markerstudio.com/technical/2010/02/introducing-the-marker-kentico-business-library-mkb/</link>
		<comments>http://www.markerstudio.com/technical/2010/02/introducing-the-marker-kentico-business-library-mkb/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 01:45:03 +0000</pubDate>
		<dc:creator>Marker</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Kentico]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://www.markerstudio.com/?p=2183</guid>
		<description><![CDATA[A complete business layer facade for  the kentico document and custom table apis. Offers strongly typed access to the custom document types and custom tables along with best practice business entities repository approach to working with kentico data.]]></description>
			<content:encoded><![CDATA[<div id="attachment_2198" class="wp-caption alignleft" style="width: 130px"><a href="/wp-content/uploads/2010/02/mkb.png"><img class="size-full wp-image-2198" title="Marker Kentico Business Library" src="/wp-content/uploads/2010/02/mkb.png" alt="Marker Kentico Business Library" width="120" height="120" /></a><p class="wp-caption-text">Marker Kentico Business Library</p></div>
<p>Marker have created a complete business layer facade for working across the kentico document apis. Why would we do such a crazy thing? Well, we found that on larger and more complex web applications that we had a certain amount of trouble with the standard approach.</p>
<p>When you use custom document types in Kentico, your rows are either returned as a CMS.TreeEngine.TreeNode or a System.Data.DataRow depending on what part of the api you are using. So the first main driver for our business layer was to be able to have a business entity class that mapped directly to a custom document type in Kentico. This means we know exactly  how a particular document type is represented in our application and know exactly what properties it has.</p>
<p>Also, you have different apis depending on whether or not you are using workflow/versioning or not.  All of the recommended development articles within the Kentico documentation generally assume you are working with published documents on your site which might not always be the case.</p>
<p>It should be noted that this approach is really for aspx template advocates looking to get the maximum control and performance from Kentico. This approach is likely overkill for smaller sites and is not applicable for the portal engine approach.</p>
<p>This article will focus on the basics of creating an entity class mapping to your custom document type and using the generic repository to perform some standard operations. There&#8217;s a lot of functionality in the MKB library beyond what is shown here and we doubt there is anything you can do with the kentico document api that you can&#8217;t do more easily and cleanly with the MKB library, if there is, let us know!</p>
<p><span style="color: #AD1230;"><strong>This library works against v5 with the 5.0.5 hot fix applied only. Just drop it in your bin folder and off you go..</strong></span></p>
<h2>Let&#8217;s create our first document entity class&#8230;</h2>
<p>You can see a sample entity below which maps to a custom document type in our application. You will need to create this for each custom document type in your application. Note that we are currently working on code generation which will automatically generate these classes for you against the Kentico database. We think this would be a great feature to have within Kentico itself at some point.</p>
<p>Make sure you entity class inherits from the DocumentEntity class (Marker.Kentico.Business.Entities.DocumentEntity). This class includes all the core fields for a kentico document instance.</p>
<p>Next, you should apply a special<strong> table attribute</strong>. The table attribute allows you to set the<em> class name </em>(maps to kentico document type&#8217;s class name) and <em>default alias path</em> (the default alias path which forms the basis of all data access for the entity by default). In addition (not shown below) there is the possibility of setting the<em> default site code </em>(default site code for all data access for the entity by default if required with multi site solutions and also a <em>default wildcard alias key (</em>for automatically loading the entity based on a wildcard alias. If you don&#8217;t set this it&#8217;s the name of the entity lowercased, in this case &#8216;supplier&#8217;).</p>
<p>Next, apply special <strong>field attributes</strong> for each property you want to map to a kentico document type. Note that your property names can be different from the underlying field if you want, and you can specific the nature of the binding (read, insert, update, all) as required.</p>
<p>This is all that is required to start using MKB, create a simply entity and move on to the next step, where the fun begins!</p>
<pre class="brush: csharp; title: ; notranslate">
using Marker.Kentico.Business.Attributes;
using Marker.Kentico.Business.Enumeration;
using Marker.Kentico.Business.Entitie;
using Marker.Kentico.Business.Attributes;
using Marker.Kentico.Business.Enumerations;
using Marker.Kentico.Business.Entities;

    public class Supplier : DocumentEntity
    {

        private string _companyName = string.Empty;

        public Supplier()
        { }

        [Field(&quot;CustomerCode&quot;, FieldBindingType.All)]
        public string CustomerCode { get; set; }

        [Field(&quot;CompanyName&quot;, FieldBindingType.All)]
        public string CompanyName {
            get { return _companyName; }
            set
            {
                _companyName = value;
                this.DocumentName = value;
            }
        }

        [Field(&quot;ImageThumb&quot;, FieldBindingType.All)]
        public Guid ImageThumb { get; set; }

        [Field(&quot;Url&quot;, FieldBindingType.All)]
        public string Url { get; set; }

        [Field(&quot;Address&quot;, FieldBindingType.All)]
        public string Address { get; set; }

        [Field(&quot;Phone&quot;, FieldBindingType.All)]
        public string Phone { get; set; }

    }
</pre>
<p>Let&#8217;s work with our entities using the document repository&#8230;</p>
<p>All you need to do is to put a using statement to the entities and repository namespaces</p>
<pre class="brush: csharp; title: ; notranslate">
using Marker.Kentico.Business.Repository;
using Marker.Kentico.Business.Entities;
</pre>
<p>Then you can retrieve a strongly typed repository to work with your supplier entities as follows. This retrieves a singleton instance of the repository class, it could also be created using dependency injection if preferred, but this is the simplest api to be offered.</p>
<pre class="brush: csharp; title: ; notranslate">
var repository = RepositoryFactory&lt;DocumentRepository&lt;Supplier&gt;&gt;.Instance;
</pre>
<p>Once you have your repository you can then load entities or get the current entity (if it is a supplier otherwise it will be null)</p>
<pre class="brush: csharp; title: ; notranslate">
Supplier supplier = repository.Load(string aliasPath);
Supplier supplier = repository.GetCurrent();
</pre>
<p>Here are some other thigns you can do&#8230;</p>
<h2>Saving and Deleting</h2>
<p>Just update your entity&#8217;s properties and call the save method</p>
<pre class="brush: csharp; title: ; notranslate">
supplier.Url = &quot;http://newurl.com&quot;;
repository.Save(supplier);
</pre>
<p>Deletion is just as easy: </p>
<pre class="brush: csharp; title: ; notranslate">
repository.Delete(supplier.DocumentID);
</pre>
<p>Custom Query Support with Paging!</p>
<p>You can see below that our repsitory enables querying with paging support (returning the total results)</p>
<pre class="brush: csharp; title: ; notranslate">
var searchCriteria = new QueryFindCriteria();
searchCriteria.QueryName = &quot;FindSuppliers&quot;; // set the query name here
searchCriteria.SelectOnlyPublished = false; // let's include unpublished nodes
searchCriteria.Take = 10; // take 10 rows
searchCriteria.Skip = 10; // start at row 11
int totalCount = 0;
List&lt;Supplier&gt; suppliers = repository.Find(searchCriteria, out totalCount);
</pre>
<p>To support this you must be running SQL 2005 or above and simply structure your query as follows.</p>
<pre class="brush: sql; title: ; notranslate">
WITH AllResults AS
(

-- core paged query should go in here

select SupplierView.*, Row_Number() over (order by ##ORDERBY## as RowIndex
FROM View_SMS_Supplier_Joined as SupplierView
##WHERE##
)

SELECT (SELECT COUNT(NodeID) FROM AllResults ) As TotalResults, *
FROM AllResults
WHERE RowIndex &gt; @skip AND RowIndex &lt;= (@skip + @take)
</pre>
<h2>Criteria objects (not overloads)</h2>
<p>You will likely have noticed that Kentico has dozens of overloads for it&#8217;s core methods. MKB gets round this by having a limited number of overloads with criteria objects that contain properties with sensible defaults for all core operations.</p>
<p>For example, the <strong>QueryFindCriteria </strong>mentioned above has the following properties.</p>
<ul>
<li>SiteName (defaults to current site)</li>
<li>CultureCode</li>
<li>Where</li>
<li>TopN</li>
<li>SelectOnlyPublished</li>
<li>OrderBy</li>
<li>CheckUserPermissions</li>
<li>QueryName</li>
<li>Parameters</li>
</ul>
<p>And there is a simpler <strong>TreeFindCriteria</strong> accepted as an overload to the Find method on any repository with these properties:</p>
<ul>
<li>SiteName (defaults to current site)</li>
<li>CultureCode</li>
<li>Where</li>
<li>TopN</li>
<li>SelectOnlyPublished</li>
<li>OrderBy</li>
<li>CheckUserPermissions</li>
<li>AliasPath</li>
<li>CombineWithDefaultCulture</li>
<li>MaxRelativeLevel</li>
<li>SelectLatestVersion &#8211; allows you to work with latest version of document under workflow, no need to change your api!</li>
</ul>
<p>We hope you can see how much simpler this is as you just need to set the properties you explcitly need for any query rather than being forced to use a particular overload.</p>
<h2>Conclusion</h2>
<p>We are sharing this library because we believe that it will be of value for kentico developers and partners to assess and make use of. We hope that it will also be useful for Kentico themselves who might consider the development of such an api to make it easier to work with Kentico.</p>
<p>This code base is provided as is and we recommend you use it for testing purposes at this stage (although we feel the api coverage is pretty good). We&#8217;ll support and answer questions as best we can. There&#8217;s lots not covered here that is offered with the library that i&#8217;ll cover in future posts if the interest is there!</p>
<h2>Get the code!</h2>
<p>We are providing a debug compiled version of our business assembly to solicit feedback on the apis offered. If there is sufficient interest we will release the code base on codeplex.</p>
<p>Download the latest version here: <a href="/wp-content/uploads/2010/02/Marker.Kentico.Business.v3.zip">Marker.Kentico.Business.v3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.markerstudio.com/technical/2010/02/introducing-the-marker-kentico-business-library-mkb/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

