<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The CodeFluent Entities Blog</title>
	<atom:link href="http://blog.codefluententities.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codefluententities.com</link>
	<description>News, and technical articles about CodeFluent Entities, a .NET model-first code generator.</description>
	<lastBuildDate>Tue, 18 Jun 2013 09:21:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.codefluententities.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/7e03ff6f604cc8ae05aba4354eda2267?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>The CodeFluent Entities Blog</title>
		<link>http://blog.codefluententities.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.codefluententities.com/osd.xml" title="The CodeFluent Entities Blog" />
	<atom:link rel='hub' href='http://blog.codefluententities.com/?pushpress=hub'/>
		<item>
		<title>[Pet Shop Reloaded] A comparative study between CodeFluent Entities and Entity Framework</title>
		<link>http://blog.codefluententities.com/2013/06/13/pet-shop-reloaded-a-comparative-study-between-codefluent-entities-and-entity-framework/</link>
		<comments>http://blog.codefluententities.com/2013/06/13/pet-shop-reloaded-a-comparative-study-between-codefluent-entities-and-entity-framework/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 16:08:19 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Pet Shop Reloaded]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3220</guid>
		<description><![CDATA[&#160; Some of you may know the story about the Pet Shop application, a .NET/C# revisited version of the original Java Pet Store application made by Sun Microsystems. These two sample applications were used as a mean to show an implementation of the best practices and features of both technologies. Today, these applications begin to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3220&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;<br />
Some of you may know the story about the <strong>Pet Shop</strong> application, a .NET/C# revisited version of the original Java <strong>Pet Store</strong> application made by <em>Sun Microsystems</em>. These two sample applications were used as a mean to show an implementation of the best practices and features of both technologies. Today, these applications begin to get dusty as they were released on November 2001 and May 2001 respectively.<br />
&nbsp;<br />
So the <a title="SoftFluent" href="http://softfluent.com" target="_blank">SoftFluent </a>team decided to build a <b>reloaded</b> version of the Pet Shop using <strong>CodeFluent Entities</strong>. To maintain the spirit of the original concept we also decided to develop a parallel version using <strong>Entity Framework</strong>.</p>
<p>&nbsp;</p>
<div id="attachment_3224" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/06/intro.png"><img class="size-large wp-image-3224" alt="Pet Shop Reloaded" src="http://codefluententities.files.wordpress.com/2013/06/intro.png?w=595&#038;h=518" width="595" height="518" /></a><p class="wp-caption-text">Pet Shop Reloaded</p></div>
<p>&nbsp;</p>
<p>Indeed, a recurrent question about CodeFluent Entities is how it relates to Entity Framework. SoftFluent has published a <a title="CodeFluent Entities &amp; the ADO.NET Entity  Framework" href="http://www.softfluent.com/docs/codefluent/codefluent-entities-entity-framework.pdf" target="_blank">white paper</a> giving a large set of details on how these two products differ so one can understand how CodeFluent Entities is much more than an <strong>ORM</strong>.<br />
&nbsp;<br />
We are going to write a series of blog posts showing how some concepts and features can (or cannot) be implemented using CodeFluent Entities and Entity Framework. We may not cover all the concepts or features of the two products (as there are many), but we will treat the main features needed to successfully implement a web application.<br />
&nbsp;</p>
<blockquote><p>We will lead this study case as objective as possible and we will love to discuss any question, remark or feedback people may give us, so don’t hesitate to comment every post.</p></blockquote>
<p>&nbsp;<br />
You can find all the blog posts related to the Pet Shop Reloaded by SoftFluent under the tag &#8220;<a title="Pet Shop Reloaded" href="http://blog.codefluententities.com/category/pet-shop-reloaded/" target="_blank">Pet Shop Reloaded</a>&#8220;. Stay tuned. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
&nbsp;<br />
&nbsp;</p>
<p>Cheers,</p>
<p>The SoftFluent team.<br />
&nbsp;<br />
&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3220/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3220&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/06/13/pet-shop-reloaded-a-comparative-study-between-codefluent-entities-and-entity-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/06/intro.png?w=595" medium="image">
			<media:title type="html">Pet Shop Reloaded</media:title>
		</media:content>
	</item>
		<item>
		<title>Using flags enumeration with ASP.NET MVC and CodeFluent Entities</title>
		<link>http://blog.codefluententities.com/2013/05/29/using-flags-enumeration-with-aspnet-mvc-and-codefluent-entities/</link>
		<comments>http://blog.codefluententities.com/2013/05/29/using-flags-enumeration-with-aspnet-mvc-and-codefluent-entities/#comments</comments>
		<pubDate>Wed, 29 May 2013 18:02:29 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Flags]]></category>
		<category><![CDATA[Multi enumeration values]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3197</guid>
		<description><![CDATA[&#160; Enumeration support &#160; &#160; CodeFluent Entities provides full support of “enumeration” types and multi value enumerations (flag enumeration). &#160; &#160; To declare a multi value enumeration, go to the enumeration type properties and set the, go to the enumeration type properties and set the Multi Value property to True. &#160; &#160; And since the build [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3197&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<h2><strong>Enumeration support</strong></h2>
<p>&nbsp;<br />
&nbsp;<br />
CodeFluent Entities provides <a title="Enumeration Support" href="http://blog.codefluententities.com/2011/03/24/enumeration-support/" target="_blank">full support of “enumeration” types</a> and multi value enumerations (flag enumeration).<br />
&nbsp;<br />
<div id="attachment_3198" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/13.png"><img class="size-full wp-image-3198" alt="Enumeration support" src="http://codefluententities.files.wordpress.com/2013/05/13.png?w=595&#038;h=217" width="595" height="217" /></a><p class="wp-caption-text">Enumeration support</p></div><br />
&nbsp;<br />
To declare a multi value enumeration, go to the enumeration type properties and set the, go to the enumeration type properties and set the <strong>Multi Value</strong> property to <strong>True</strong>.<br />
&nbsp;<br />
<div id="attachment_3199" class="wp-caption aligncenter" style="width: 521px"><a href="http://codefluententities.files.wordpress.com/2013/05/23.png"><img class="size-full wp-image-3199" alt="Multi Value flag" src="http://codefluententities.files.wordpress.com/2013/05/23.png?w=595"   /></a><p class="wp-caption-text">Multi Value flag</p></div><br />
&nbsp;<br />
And since the build version (<a href="http://blog.codefluententities.com/2012/03/16/new-codefluent-entities-version-released/" target="_blank">646</a>) you can set an enumeration value as the combination of other values (by their name).<br />
&nbsp;<br />
<div id="attachment_3200" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/32.png"><img class="size-full wp-image-3200" alt="Enumeration value" src="http://codefluententities.files.wordpress.com/2013/05/32.png?w=595&#038;h=409" width="595" height="409" /></a><p class="wp-caption-text">Enumeration value</p></div><br />
&nbsp;</p>
<h2></strong>Using enumeration values with ASP.NET MVC</strong></h2>
<p>&nbsp;<br />
Let’s use these concepts on an <strong>ASP.NET MVC</strong> application, I will use the model above as an example. I also have a <em>MediaController</em> with an <em>Index</em> action to list all Medias and an <em>Edit</em> action (Get and Post).<br />
&nbsp;<br />
The default template for an enumeration value is a <em>textbox</em>, so if I write something like this:</p>
<pre class="brush: plain; title: ; notranslate">
@Html.EditorFor(m =&gt; m.MediaType)
</pre>
<p>&nbsp;<br />
I will get a <em>textbox</em> for my enumeration value.<br />
&nbsp;<br />
<div id="attachment_3201" class="wp-caption aligncenter" style="width: 494px"><a href="http://codefluententities.files.wordpress.com/2013/05/42.png"><img class="size-full wp-image-3201" alt="Textbox for enumeration value" src="http://codefluententities.files.wordpress.com/2013/05/42.png?w=595"   /></a><p class="wp-caption-text">Textbox for enumeration value</p></div><br />
&nbsp;<br />
This will work but the user will have to write a correct enumeration value, and unless each user knows all the possible enumeration values, this is not an acceptable solution.<br />
&nbsp;<br />
It would be better to display a <strong>dropdown list</strong> instead. Let’s create a template named <em>Choice.cshtml</em> on the <strong><em>Views\Shared\EditorTemplates</em></strong> folder.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
@model Enum
@{
var items = from object value in Enum.GetValues(Model.GetType())
select new { Value = value, Text = value.ToString() };
SelectList list = new SelectList(items, &quot;Value&quot;, &quot;Text&quot;, Model);
}
@Html.DropDownList(&quot;&quot;, list)
</pre>
<p>&nbsp;<br />
And now if we choose this as the template for our enumeration:<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
@Html.EditorFor(m =&gt; m.MediaType, &quot;Choice&quot;)
</pre>
<p>&nbsp;<br />
<div id="attachment_3202" class="wp-caption aligncenter" style="width: 468px"><a href="http://codefluententities.files.wordpress.com/2013/05/52.png"><img class="size-full wp-image-3202" alt="Dropdown list for enumeration" src="http://codefluententities.files.wordpress.com/2013/05/52.png?w=595"   /></a><p class="wp-caption-text">Dropdown list for enumeration</p></div><br />
&nbsp;<br />
This works fine and we can use the <em>Choice.cshtml</em> template for any enumeration type.<br />
&nbsp;</p>
<h2></strong>Using multi enumeration values with ASP.NET MVC</strong></h2>
<p>&nbsp;<br />
Let’s now do the same work for a multi value enumeration (flag enumeration). First we create a template named <em>MultiChoice.cshtml</em> on the <strong><em>Views\Shared\EditorTemplates</em></strong> folder.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
@model Enum
@{
var items = from object value in Enum.GetValues(Model.GetType())
select new { Value = value, Text = value.ToString() };
IEnumerable selected = CodeFluent.Runtime.Utilities.ConvertUtilities.SplitEnumValues(Model);
MultiSelectList list = new MultiSelectList(items, &quot;Value&quot;, &quot;Text&quot;, selected);
}
@Html.DropDownList(&quot;&quot;, list, new { multiple = &quot;multiple&quot; })
</pre>
<p>&nbsp;<br />
We use here a method on the <strong>CodeFluent.Runtime.Utilities</strong> namespace to split a flag value into a list of enumeration values.<br />
Let’s try it for our multi value enumeration.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
@Html.EditorFor(m =&gt; m.ReleaseFormat, &quot;MultiChoice&quot;)
</pre>
<p>&nbsp;<br />
<div id="attachment_3203" class="wp-caption aligncenter" style="width: 502px"><a href="http://codefluententities.files.wordpress.com/2013/05/62.png"><img class="size-full wp-image-3203" alt="Multiple dropdown list for enumeration" src="http://codefluententities.files.wordpress.com/2013/05/62.png?w=595"   /></a><p class="wp-caption-text">Multiple dropdown list for enumeration</p></div><br />
&nbsp;<br />
This seems to work but it doesn&#8217;t, when I try to save my form, not all values are saved (from the flag multi value enumeration). This is because <strong>MVC does not bind correctly the multi value enumeration to my model.</strong><br />
&nbsp;<br />
We need to add a custom model binder (<em><strong><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.imodelbinder(v=vs.108).aspx" target="_blank">System.Web.Mvc.IModelBinder</a></strong></em>) and a value provider (<em><strong><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.ivalueprovider(v=vs.108).aspx" target="_blank">System.Web.Mvc.IValueProvider</a></strong></em>). I will use some utilities classes that are used for the <strong>ASP.NET Web Site V2</strong> producer, they can be found under the <em>Templates</em> folder in the CodeFluent Entities installation location (<strong>Program Files (x86)\SoftFluent\CodeFluent\Modeler\Templates\UI\AspNetMvc\Code\Utilities.cs.tpl</strong>). I will copy the content of the file in my ASP.NET MVC project filling the correct namespace. Don’t forget to add a reference to the <strong>CodeFluent.Runtime.Web</strong> assembly.<br />
&nbsp;<br />
<div id="attachment_3204" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/72.png"><img class="size-full wp-image-3204" alt="EntityBinder and EntityValueProvider" src="http://codefluententities.files.wordpress.com/2013/05/72.png?w=595&#038;h=136" width="595" height="136" /></a><p class="wp-caption-text">EntityBinder and EntityValueProvider</p></div><br />
&nbsp;<br />
Finally, we register the <strong>EntityBinder</strong> and the <strong>EntityValueProviderFactory</strong> classes that we have just added. On the Application Start:<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
ValueProviderFactories.Factories.Add(new EntityValueProviderFactory());
ModelBinderProviders.BinderProviders.Add(new EntityBinder());
</pre>
<p>&nbsp;<br />
This time everything works great.<br />
&nbsp;<br />
This post was inspired by the CodeFluent Entities templates when wondering what the <strong>ASP.NET Web Site V2</strong> producer generates <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style:none;" alt="Winking smile" src="http://codefluententities.files.wordpress.com/2012/05/wlemoticon-winkingsmile.png?w=595" />.<br />
&nbsp;<br />
&nbsp;<br />
Regards,<br />
&nbsp;<br />
&nbsp;<br />
Pablo Fernandez Duran<br />
&nbsp;<br />
&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3197&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/05/29/using-flags-enumeration-with-aspnet-mvc-and-codefluent-entities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/13.png" medium="image">
			<media:title type="html">Enumeration support</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/23.png" medium="image">
			<media:title type="html">Multi Value flag</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/32.png" medium="image">
			<media:title type="html">Enumeration value</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/42.png" medium="image">
			<media:title type="html">Textbox for enumeration value</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/52.png" medium="image">
			<media:title type="html">Dropdown list for enumeration</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/62.png" medium="image">
			<media:title type="html">Multiple dropdown list for enumeration</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/72.png" medium="image">
			<media:title type="html">EntityBinder and EntityValueProvider</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2012/05/wlemoticon-winkingsmile.png" medium="image">
			<media:title type="html">Winking smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Defining type mappers when importing a database using the Importer Wizard</title>
		<link>http://blog.codefluententities.com/2013/05/29/defining-type-mappers-when-importing-a-database-using-the-importer-wizard/</link>
		<comments>http://blog.codefluententities.com/2013/05/29/defining-type-mappers-when-importing-a-database-using-the-importer-wizard/#comments</comments>
		<pubDate>Wed, 29 May 2013 09:53:57 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Importers]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3186</guid>
		<description><![CDATA[You can use the Importer Wizard to import an existing data base as a CodeFluent Entities model. You can access the Importer from the Modeler or the solution explorer on your CodeFluent Entities project (right click). &#160; &#160; The importer makes a mapping between the data source types and the CodeFluent Entities types. But, you [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3186&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>You can use the Importer Wizard to import an existing data base as a CodeFluent Entities model. You can access the Importer from the Modeler or the solution explorer on your CodeFluent Entities project (right click).<br />
&nbsp;<br />
<div id="attachment_3187" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/12.png"><img class="size-full wp-image-3187" alt="The Importer Wizard" src="http://codefluententities.files.wordpress.com/2013/05/12.png?w=595&#038;h=251" width="595" height="251" /></a><p class="wp-caption-text">The Importer Wizard</p></div><br />
&nbsp;<br />
The importer makes a mapping between the data source types and the <a title="CodeFluent Entities Types" href="http://www.softfluent.com/documentation/webframe.html?ModelDesign_Types.html" target="_blank">CodeFluent Entities types</a>. But, you may want to define your own mapping configuration for a given type.<br />
&nbsp;<br />
To do that, go to the “<strong>advanced properties</strong>” of the Importer Wizard and select “<strong>Type Mappers</strong>” under the “<strong>Input Mapping</strong>” group and add your type mapper.<br />
&nbsp;<br />
<div id="attachment_3188" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/22.png"><img class="size-full wp-image-3188" alt="Type Mappers Configuration" src="http://codefluententities.files.wordpress.com/2013/05/22.png?w=595&#038;h=672" width="595" height="672" /></a><p class="wp-caption-text">Type Mappers Configuration</p></div><br />
&nbsp;<br />
<div id="attachment_3189" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/31.png"><img class="size-full wp-image-3189" alt="Add an Importer Type Mapper" src="http://codefluententities.files.wordpress.com/2013/05/31.png?w=595&#038;h=405" width="595" height="405" /></a><p class="wp-caption-text">Add an Importer Type Mapper</p></div><br />
&nbsp;<br />
Let’s say I am importing a SQL Server 2012 database and I have a field of type “<em><a title="time (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/bb677243.aspx" target="_blank">time</a></em>” (more information about SQL Server 2012 type mapping <a title="Mapping CLR Parameter Data" href="http://msdn.microsoft.com/en-us/library/ms131092(v=sql.110).aspx" target="_blank">here</a>), well I would like to have a CLR type &#8220;<em>TimeSpan&#8221;</em> mapped to it. When I take a look at the imported model I can see that the mapped type is “<em>time</em>”, but when I generate the Business Object Model (BOM) layer I have a property of type “<em>System.DateTime </em>(nullable)”. This is because the SQL Server type “<em>time</em>” did not exist before the SQL Server 2008 version.<br />
&nbsp;<br />
<div id="attachment_3190" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/41.png"><img class="size-full wp-image-3190" alt="SQL Server time type" src="http://codefluententities.files.wordpress.com/2013/05/41.png?w=595&#038;h=110" width="595" height="110" /></a><p class="wp-caption-text">SQL Server time type</p></div><br />
&nbsp;<br />
<div id="attachment_3191" class="wp-caption aligncenter" style="width: 475px"><a href="http://codefluententities.files.wordpress.com/2013/05/51.png"><img class="size-full wp-image-3191" alt="time to DateTime mapping" src="http://codefluententities.files.wordpress.com/2013/05/51.png?w=595"   /></a><p class="wp-caption-text">time to DateTime mapping</p></div><br />
&nbsp;<br />
So we can define a “<strong>type mapper</strong>” for the SQL Server type “<em>time</em>”.<br />
&nbsp;<br />
<div id="attachment_3192" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/61.png"><img class="size-full wp-image-3192" alt="elapsedtime mapper" src="http://codefluententities.files.wordpress.com/2013/05/61.png?w=595&#038;h=404" width="595" height="404" /></a><p class="wp-caption-text">elapsedtime mapper</p></div><br />
&nbsp;</p>
<blockquote><p>We could also have chosen &#8220;<em>System.TimeSpan&#8221;</em>, &#8220;<em>timespan&#8221;</em> or &#8220;<em>duration&#8221;</em> as the “<strong>Type Name</strong>”.</p></blockquote>
<p>&nbsp;<br />
And now we have a CLR type “<em>System.TimeSpan </em>(nullable)” in our BOM for a SQL Server 2012 type “<em>time</em>”.<br />
&nbsp;<br />
<div id="attachment_3193" class="wp-caption aligncenter" style="width: 465px"><a href="http://codefluententities.files.wordpress.com/2013/05/71.png"><img class="size-full wp-image-3193" alt="time to TimeSpan mapping" src="http://codefluententities.files.wordpress.com/2013/05/71.png?w=595"   /></a><p class="wp-caption-text">time to TimeSpan mapping</p></div><br />
&nbsp;</p>
<blockquote><p>
Remember that you can save your <a title="CodeFluent Entities: Saving import configurations" href="http://blog.codefluententities.com/2012/07/11/codefluent-entities-saving-import-configurations/" target="_blank">Importer Wizard configuration</a>.</p></blockquote>
<p>&nbsp;<br />
You can find more resources about the Importer Wizard <a title="Importer Wizard" href="http://blog.codefluententities.com/category/importers/" target="_blank">here</a>.<br />
&nbsp;<br />
&nbsp;<br />
Regards,<br />
&nbsp;<br />
Pablo Fernandez Duran<br />
&nbsp;<br />
&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3186/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3186&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/05/29/defining-type-mappers-when-importing-a-database-using-the-importer-wizard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/12.png" medium="image">
			<media:title type="html">The Importer Wizard</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/22.png" medium="image">
			<media:title type="html">Type Mappers Configuration</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/31.png" medium="image">
			<media:title type="html">Add an Importer Type Mapper</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/41.png" medium="image">
			<media:title type="html">SQL Server time type</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/51.png" medium="image">
			<media:title type="html">time to DateTime mapping</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/61.png" medium="image">
			<media:title type="html">elapsedtime mapper</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/71.png" medium="image">
			<media:title type="html">time to TimeSpan mapping</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a custom sub producer to only generate resources</title>
		<link>http://blog.codefluententities.com/2013/05/16/creating-a-custom-sub-producer-to-only-generate-resources/</link>
		<comments>http://blog.codefluententities.com/2013/05/16/creating-a-custom-sub-producer-to-only-generate-resources/#comments</comments>
		<pubDate>Thu, 16 May 2013 11:20:50 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Producers]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3164</guid>
		<description><![CDATA[Generating a CodeFluent Entities model looks at all the producers, and produce each one of them, assuming they have been enabled. The BOM producer is the most important producer and generates classes from your entities. If we break down that producer, we realize that it produces different things, such as templates, resources, membership providers, membership [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3164&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Generating a CodeFluent Entities model looks at all the producers, and produce each one of them, assuming they have been enabled. The BOM producer is the most important producer and generates classes from your entities. If we break down that producer, we realize that it produces different things, such as templates, resources, membership providers, membership roles, constants&#8230;</p>
<p>What if you wanted to only produce resources, and nothing else?<br />
One reason would be that your project has a lot of entities, your model is pretty much finished, but you still need to add resources. Moreover, your project is hosted on TFS online, and you do not want to check out, and check in, all the new generated files, especially if they have not changed!</p>
<p>By default, TFS checks out all the modified files (by a human or a code generator). Then, you need to check them back in. Hosted online, this means that the check in process would contain almost all the files of your BOM and it could be time consuming.</p>
<p>In this post we will create a custom sub producer that will only generate resources, and nothing else.</p>
<p><strong>1. Creating the project</strong></p>
<p>First, you need to create a new class library project, add some of the CodeFluent Entities references as well as 2 classes (BuildOnlyResources.cs and Constants.cs):</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/05/solution1.png"><img class="size-full wp-image-3166 aligncenter" alt="class library project" src="http://codefluententities.files.wordpress.com/2013/05/solution1.png?w=595"   /></a></p>
<p><strong>2. Writing classes</strong></p>
<p>The BuildOnlyResources class extends the ICodeDomSubProducer interface to plug itself into the OnCodeDomProduction event. The first thing to do is to cancel the production of everything besides Resources. To do this, we check the eventType retrieved from the parameter of the OnCodeDomProduction method, and set the cancel property to true.</p>
<p>At this stage, the sub producer will stop generating all files, except the resources. Meanwhile, it will also delete the existing files, which is not what we want! We want to keep the existing files, without modifying them. This part is handled when the eventType corresponds to the UnitProducing value. There, we go through each class, and pretend they have been generated. That way, they will not be deleted if they exist. The method that does this is the <strong>AddToGeneratedFiles(path) </strong>method from the baseProducer class.</p>
<p>The Constants class simply contains 2 constants, used int the BuildOnlyResources class.</p>
<p><strong>3. Adding options</strong></p>
<p>We need to add a couple of options for our sub producer. The first is a boolean option that describes whether the sub producer is enabled or not. If not enabled, it will not be used during the generation. The second option is a boolean that describes whether the resources are produced or not.</p>
<p><strong>4. Compiling the solution</strong></p>
<p>We can now compile the solution in release mode and obtain a dll, called SubProducerResources.dll. In order to use that sub producer in our CodeFluent Entities model, we need to add this dll to the folder where CodeFluent Entities was installed, located at <em>C:\Program Files (x86)\SoftFluent\CodeFluent\Modeler</em> by default.</p>
<p><strong>5. Displaying the subproducer in the modeler.</strong></p>
<p>The last step is to be able to display that sub producer in the modeler. CodeFluent Entities looks at a config file located in: C:\Users\{user}\AppData\Roaming\CodeFluent.Modeler.Design\Custom.config. You need to create it because it does not exist. Its content needs to look  like this:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;codeFluent.Modeler&gt;
 &lt;producerDescriptors&gt;
 &lt;producerDescriptor name=&quot;SubProducerResources&quot; displayName=&quot;SubProducer Resources&quot; category=&quot;My Custom Producers&quot; typeName=&quot;SubProducerResources.BuildOnlyResources, SubProducerResources&quot; /&gt;
 &lt;/producerDescriptors&gt;
&lt;/codeFluent.Modeler&gt;
</pre>
<p><strong>6. Ready</strong></p>
<p>Your sub producer is ready to be used! Open your CodeFluent Entities project, right-click on your BOM producer, and add a new sub producer. You should see your sub producer in the list:</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/05/addsubprod.png"><img class="size-full wp-image-3168 aligncenter" alt="custom sub producer" src="http://codefluententities.files.wordpress.com/2013/05/addsubprod.png?w=595&#038;h=436" width="595" height="436" /></a></p>
<p>Once added, it will appear under your BOM producer:</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/05/model.png"><img class="size-full wp-image-3169 aligncenter" alt="Custom Sub Producer" src="http://codefluententities.files.wordpress.com/2013/05/model.png?w=595"   /></a></p>
<p>Here is what you are really looking for, the code for both BuildOnlyResources and Constants classes:</p>
<pre class="brush: plain; title: ; notranslate">
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Xml;
using CodeFluent.Model;
using CodeFluent.Model.Common.Design;
using CodeFluent.Model.Design;
using CodeFluent.Producers.CodeDom;
using CodeFluent.Runtime.Utilities;

namespace SubProducerResources
{
    [Category(&quot;Business Layer Producers&quot;)]
    [DisplayName(&quot;SubProducer Resources&quot;)]
    [Producer(Constants.CustomResourcesProducerNamespaceUri, Constants.CustomResourcesProducerNamespacePrefix)]
    public class BuildOnlyResources : ICodeDomSubProducer
    {
        private CodeDomBaseProducer _baseProducer;
        private CodeFluent.Producers.CodeDom.SubProducer _subProducer;

        [Description(&quot;Determines if sub producer is enabled.&quot;)]
        [Category(&quot;Configuration&quot;)]
        [DefaultValue(true)]
        [DisplayName(&quot;Is Enabled&quot;)]
        [ModelLevel(ModelLevel.Normal)]
        public virtual bool Enabled
        {
            get
            {
                return XmlUtilities.GetAttribute(Element, &quot;enabled&quot;, true);
            }
            set
            {
                XmlUtilities.SetAttribute(Element, &quot;enabled&quot;, value.ToString().ToLowerInvariant());
            }
        }

        [Description(&quot;Determines if resources are produced.&quot;)]
        [Category(&quot;Configuration&quot;)]
        [DefaultValue(true)]
        [DisplayName(&quot;Produce Resources&quot;)]
        [ModelLevel(ModelLevel.Normal)]
        public virtual bool ProduceResources
        {
            get
            {
                return XmlUtilities.GetAttribute(Element, &quot;produceResources&quot;, true);
            }
            set
            {
                XmlUtilities.SetAttribute(Element, &quot;produceResources&quot;, value.ToString().ToLowerInvariant());
            }
        }

        public virtual void Initialize(CodeDomBaseProducer baseProducer, CodeFluent.Producers.CodeDom.SubProducer subProducer, IDictionary context)
        {
            _baseProducer = baseProducer;
            _subProducer = subProducer;
            baseProducer.CodeDomProduction += OnCodeDomProduction;
        }

        public virtual void Produce(IDictionary context, CodeCompileUnit unit)
        {
        }

        public virtual void Terminate(IDictionary context)
        {
        }

        private void OnCodeDomProduction(object sender, CodeDomProductionEventArgs e)
        {
            if (!Enabled)
                return;

            if (e.EventType == CodeDomProductionEventType.ResourcesProducing)
            {
                if (!ProduceResources)
                {
                    e.Cancel = true;
                }
            }
            if (e.EventType == CodeDomProductionEventType.UnitsProducing)
            {
                e.Cancel = true;
                IEnumerable&lt;CodeCompileUnit&gt; units = (CodeCompileUnit[])e.Argument;
                foreach (CodeCompileUnit unit in units)
                {
                    FakeProduceUnit(unit);
                }
            }
            // adapt to your needs
            if (e.EventType == CodeDomProductionEventType.ConstantsProducing ||
                e.EventType == CodeDomProductionEventType.SRProducing ||
                e.EventType == CodeDomProductionEventType.BasicAuthenticationModuleProducing ||
                e.EventType == CodeDomProductionEventType.BitsServerProducing ||
                e.EventType == CodeDomProductionEventType.MembershipProviderProducing ||
                e.EventType == CodeDomProductionEventType.MembershipUserProducing ||
                e.EventType == CodeDomProductionEventType.ProfileProviderProducing ||
                e.EventType == CodeDomProductionEventType.RoleProviderProducing)
            {
                e.Cancel = true;
            }
        }

        private void FakeProduceUnit(CodeCompileUnit unit)
        {
            if (unit == null)
                throw new ArgumentNullException(&quot;unit&quot;);

            BaseType baseType = UserData.GetBaseType(unit); // get the type related to this unit, if any
            if (baseType == null)
                return;

            // check if the type was to be produced or not

            if (!_baseProducer.MustProduce(baseType, CodeFluent.Producers.CodeDom.Constants.ModelProducerNamespaceUri))
                return;

            Set set = baseType as Set;
            if (set != null)
            {
                if (!_baseProducer.MustProduce(set.ItemEntity, CodeFluent.Producers.CodeDom.Constants.ModelProducerNamespaceUri))
                    return;
            }

            // determine the final target path where the file should have gone, and pretend it's been generated
            string path = ((CodeDomProducer)_baseProducer).GetTargetPath(baseType);
            path = _baseProducer.GetProductionTargetPath(baseType, path, false, false);

            if (File.Exists(path))
            {
                _baseProducer.AddToGeneratedFiles(path);
            }
        }

        public XmlElement Element
        {
            get
            {
                if (_subProducer == null)
                    throw new CodeFluentCodeDomProducerException(GetType().FullName);

                return _subProducer.Element;
            }
            set
            {
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SubProducerResources
{
    public sealed class Constants
    {
        public const string CustomResourcesProducerNamespaceUri = &quot;http://www.softfluent.com/codefluent/producers.customResources/2013/1&quot;;
        public const string CustomResourcesProducerNamespacePrefix = &quot;cfcr&quot;;

        private Constants()
        {
        }
    }
}
</pre>
<p>Vincent Patry</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3164&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/05/16/creating-a-custom-sub-producer-to-only-generate-resources/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/solution1.png" medium="image">
			<media:title type="html">class library project</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/addsubprod.png" medium="image">
			<media:title type="html">custom sub producer</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/model.png" medium="image">
			<media:title type="html">Custom Sub Producer</media:title>
		</media:content>
	</item>
		<item>
		<title>Exploring the CodeFluent Runtime: ChunkedMemoryStream</title>
		<link>http://blog.codefluententities.com/2013/05/15/exploring-the-codefluent-runtime-chunkedmemorystream/</link>
		<comments>http://blog.codefluententities.com/2013/05/15/exploring-the-codefluent-runtime-chunkedmemorystream/#comments</comments>
		<pubDate>Wed, 15 May 2013 21:48:01 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Exploring the CodeFluent Runtime]]></category>
		<category><![CDATA[ChunkedMemoryStream]]></category>
		<category><![CDATA[Large Object Heap]]></category>
		<category><![CDATA[Memory Stream]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3157</guid>
		<description><![CDATA[&#160; Today, on the series “Exploring the CodeFluent Runtime” we are going to take a look at the ChunkedMemoryStream class on the CodeFluent.Runtime.Utilities namespace. &#160; This class allows you to manipulate a memory stream by “chunks”. This can be useful when you are dealing with memory streams big enough (85,000 bytes) to be allocated on [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3157&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;<br />
Today, on the series “<a title="Exploring the CodeFluent Runtime" href="http://blog.codefluententities.com/category/exploring-the-codefluent-runtime/" target="_blank">Exploring the CodeFluent Runtime</a>” we are going to take a look at the <strong>ChunkedMemoryStream </strong>class on the <em>CodeFluent.Runtime.Utilities</em> namespace.<br />
&nbsp;<br />
This class allows you to manipulate a memory stream by “chunks”. This can be useful when you are dealing with memory streams big enough (85,000 bytes) to be allocated on the <strong>Large Object Heap</strong> (LOH).<br />
&nbsp;<br />
The <strong>ChunkedMemoryStream</strong> can be used instead of the <em>System.IO.MemoryStream (mscorlib.dll)</em> to avoid memory fragmentation.<br />
&nbsp;<br />
Let’s build a simple example in order to compare the use of a <em>System.IO.MemoryStream</em> against the <em>CodeFluent.Runtime.Utilities.ChunkedMemoryStream</em>.<br />
&nbsp;<br />
Let’s say I want to load a file’s content in memory (big enough to sit on the LOH).<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
static void Main(string[] args)
{
  FileStream fileSm = new FileStream(@&quot;file_path&quot;, FileMode.Open);
  Stream ms = new MemoryStream();
  fileSm.CopyTo(ms);
  ms.Close();
  fileSm.Close();

  System.Diagnostics.Debugger.Break();
}
</pre>
<p>&nbsp;<br />
When the Debugger breaks let’s explore the LOH:<br />
&nbsp;<br />
<div id="attachment_3158" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/11.png"><img class="size-full wp-image-3158" alt="LOH using MemoryStream" src="http://codefluententities.files.wordpress.com/2013/05/11.png?w=595&#038;h=782" width="595" height="782" /></a><p class="wp-caption-text">LOH using MemoryStream</p></div><br />
&nbsp;<br />
We can see that the LOH size is (17184 + 41943056 + 83886096 = 125846336 bytes) and we easily distinguish a memory allocation for 2 byte arrays (perhaps some buffers used internally when copying the data from one stream to another).<br />
&nbsp;<br />
Let’s now change only one line in our code example and use the <strong>CodeFluent.Runtime.Utilities.ChunkedMemoryStream</strong>.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
static void Main(string[] args)
{
  FileStream fileSm = new FileStream(@&quot;file_path&quot;, FileMode.Open);
  Stream ms = new CodeFluent.Runtime.Utilities.ChunkedMemoryStream();
  fileSm.CopyTo(ms);
  ms.Close();
  fileSm.Close();

  System.Diagnostics.Debugger.Break();
}
</pre>
<p>&nbsp;<br />
And let’s explore the LOH:<br />
&nbsp;<br />
<div id="attachment_3159" class="wp-caption aligncenter" style="width: 603px"><a href="http://codefluententities.files.wordpress.com/2013/05/21.png"><img class="size-full wp-image-3159" alt="LOH using ChunkedMemoryStream" src="http://codefluententities.files.wordpress.com/2013/05/21.png?w=595"   /></a><p class="wp-caption-text">LOH using ChunkedMemoryStream</p></div><br />
&nbsp;<br />
We now see that the LOH size is 17184 bytes and we cannot see any trace of a byte array.<br />
&nbsp;</p>
<blockquote><p>Using the <strong>ChunkedMemoryStream</strong> we avoid allocating memory on the LOH when manipulating big streams.</p></blockquote>
<p>&nbsp;<br />
Remeber that the CodeFluent Runtime Client is a free library that provides very useful and powerful helpers like:</p>
<ul>
<li>XML utilities</li>
<li>IO utilities</li>
<li>Type conversion helpers</li>
<li>JSON utilities</li>
<li>… and many <a title="The CodeFluent Entities Runtime Client" href="http://www.softfluent.com/products/codefluent-runtime-client" target="_blank">other</a></li>
</ul>
<p>&nbsp;<br />
You can easily install the CodeFluent Runtime Client from <a title="CodeFluent Entities Runtime Client on Nuget" href="https://nuget.org/packages/CodeFluentRuntimeClient" target="_blank">Nugget</a>.<br />
&nbsp;<br />
<em>PM&gt; Install-package CodeFluentRuntimeClient</em><br />
&nbsp;<br />
&nbsp;<br />
Regards,<br />
&nbsp;<br />
Pablo Fernadez Duran<br />
&nbsp;<br />
&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3157/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3157&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/05/15/exploring-the-codefluent-runtime-chunkedmemorystream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/11.png" medium="image">
			<media:title type="html">LOH using MemoryStream</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/21.png" medium="image">
			<media:title type="html">LOH using ChunkedMemoryStream</media:title>
		</media:content>
	</item>
		<item>
		<title>Patch text files after code generation with CodeFluent Entities</title>
		<link>http://blog.codefluententities.com/2013/05/15/patch-text-files-after-code-generation-with-codefluent-entities/</link>
		<comments>http://blog.codefluententities.com/2013/05/15/patch-text-files-after-code-generation-with-codefluent-entities/#comments</comments>
		<pubDate>Wed, 15 May 2013 13:28:02 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Producers]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Patch]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3143</guid>
		<description><![CDATA[&#160; CodeFluent Entities provides a large set of concepts and tools to generate code as custom as wanted. But, it may be a reason you need to modify the output produced by the CodeFluent Entities engine when there is not an option or a feature that allows you do that. &#160; The Patch Producer is [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3143&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;<br />
CodeFluent Entities provides a large set of concepts and tools to generate code as custom as wanted. But, it may be a reason you need to modify the output produced by the CodeFluent Entities engine when there is not an option or a feature that allows you do that.<br />
&nbsp;<br />
The <strong><a href="http://www.softfluent.com/documentation/webframe.html?StandardProducers_PatchProducer.html" title="The Patch Producer" target="_blank">Patch Producer</a></strong> is a producer that lets you “<em>patch</em>” text files using regular expressions. You can find the Patch Producer under the Utility Producers category.<br />
&nbsp;<br />
<div id="attachment_3144" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/1.png"><img class="size-full wp-image-3144" alt="Patch producer" src="http://codefluententities.files.wordpress.com/2013/05/1.png?w=595&#038;h=215" width="595" height="215" /></a><p class="wp-caption-text">Patch producer</p></div><br />
&nbsp;<br />
<div id="attachment_3145" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/2.png"><img class="size-full wp-image-3145" alt="Add a Patch" src="http://codefluententities.files.wordpress.com/2013/05/2.png?w=595&#038;h=403" width="595" height="403" /></a><p class="wp-caption-text">Add a Patch</p></div><br />
&nbsp;<br />
<strong>Path</strong>: can be a directory path or a file path. If relative, it is based from the directory containing the project root part.<br />
<strong>File Search Pattern</strong>: is a file filter expression. Only used if “<strong>path</strong>” is a directory.<br />
<strong>Search Pattern</strong>: a <a title="Grouping Constructs in Regular Expressions" href="http://msdn.microsoft.com/en-us/library/bs2twtah.aspx" target="_blank">regular expression matching groups</a>.<br />
<strong>Replace</strong>: a key=value pair list separated by the “<strong>Replace Separator Character</strong>”.<br />
&nbsp;</p>
<blockquote><p>You can use the default namespace in the path attribute using the syntax <em>{1:DefaultNameSpace}</em></p></blockquote>
<p>&nbsp;<br />
&nbsp;</p>
<h2><strong>Example 1</strong></h2>
<p>&nbsp;<br />
CodeFluent Entities provides a “<em>tracking</em>” feature.<br />
&nbsp;<br />
<div id="attachment_3146" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/3.png"><img class="size-full wp-image-3146" alt="Tracking User Name" src="http://codefluententities.files.wordpress.com/2013/05/3.png?w=595&#038;h=18" width="595" height="18" /></a><p class="wp-caption-text">Tracking User Name</p></div><br />
&nbsp;<br />
In most of the cases the <em>CodeFluentUser.Name</em> is of the form “<em>Domain\UserName</em>” and let’s say we only want to store in the database the “<em>UserName</em>” without the “Domain” (ie. The <em>CodeFluentUser.UserName</em>).<br />
&nbsp;<br />
In my case I have a CodeFluent Entities project with a Business Object Model (BOM) producer and a SQL Server persistence producer. The BOM generated files are stored in a class library project having as name the default namespace.<br />
&nbsp;<br />
So, I need to search all files matching “<strong> *.cs</strong> ” in my BOM project:<br />
&nbsp;<br />
<div id="attachment_3147" class="wp-caption aligncenter" style="width: 413px"><a href="http://codefluententities.files.wordpress.com/2013/05/5.png"><img class="size-full wp-image-3147" alt=".cs Search Path" src="http://codefluententities.files.wordpress.com/2013/05/5.png?w=595"   /></a><p class="wp-caption-text">.cs Search Path</p></div><br />
&nbsp;<br />
And make the replacement using the regular expression:<br />
<strong>,\s*persistence\.Context\.User\.(?&lt;name&gt;Name)\s*\)</strong><br />
&nbsp;<br />
And replace the matched value in the group name “<em>name</em>” by “<em>UserName</em>”:<br />
&nbsp;<br />
<div id="attachment_3148" class="wp-caption aligncenter" style="width: 600px"><a href="http://codefluententities.files.wordpress.com/2013/05/6.png"><img class="size-full wp-image-3148" alt="UserName replace" src="http://codefluententities.files.wordpress.com/2013/05/6.png?w=595"   /></a><p class="wp-caption-text">UserName replace</p></div><br />
&nbsp;<br />
If I build my CodeFluent Entities, now I have:<br />
&nbsp;<br />
<div id="attachment_3149" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/4.png"><img class="size-full wp-image-3149" alt="UserName replaced" src="http://codefluententities.files.wordpress.com/2013/05/4.png?w=595&#038;h=42" width="595" height="42" /></a><p class="wp-caption-text">UserName replaced</p></div><br />
&nbsp;<br />
&nbsp;</p>
<h2><strong>Example 2</strong></h2>
<p>&nbsp;<br />
CodeFluent Entities adds some information on each generated file about the generation itself. For example, for SQL files:<br />
&nbsp;<br />
<div id="attachment_3150" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/7.png"><img class="size-full wp-image-3150" alt="Generation information" src="http://codefluententities.files.wordpress.com/2013/05/7.png?w=595&#038;h=18" width="595" height="18" /></a><p class="wp-caption-text">Generation information</p></div><br />
&nbsp;<br />
Let’s say we want to add the name our company within this information, something like “<em>CodeFluent Generated for SoftFluent […]</em>”<br />
We add a new “<em>Patch</em>” producer.<br />
&nbsp;<br />
<div id="attachment_3151" class="wp-caption aligncenter" style="width: 530px"><a href="http://codefluententities.files.wordpress.com/2013/05/8.png"><img class="size-full wp-image-3151" alt="Generation information Patch" src="http://codefluententities.files.wordpress.com/2013/05/8.png?w=595"   /></a><p class="wp-caption-text">Generation information Patch</p></div><br />
&nbsp;<br />
As you can see, I store my SQL files in a folder named “SQL” in the same location as my BOM generated files (cf. <strong>example 1</strong>).<br />
&nbsp;<br />
We build the CodeFluent Entities project and now we have:<br />
&nbsp;<br />
<div id="attachment_3152" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/05/9.png"><img class="size-full wp-image-3152" alt="Generation information Patched" src="http://codefluententities.files.wordpress.com/2013/05/9.png?w=595&#038;h=22" width="595" height="22" /></a><p class="wp-caption-text">Generation information Patched</p></div><br />
&nbsp;<br />
Have fun.<br />
&nbsp;<br />
Regards,<br />
Pablo Fernandez Duran<br />
&nbsp;<br />
&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3143&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/05/15/patch-text-files-after-code-generation-with-codefluent-entities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/1.png" medium="image">
			<media:title type="html">Patch producer</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/2.png" medium="image">
			<media:title type="html">Add a Patch</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/3.png" medium="image">
			<media:title type="html">Tracking User Name</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/5.png" medium="image">
			<media:title type="html">.cs Search Path</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/6.png" medium="image">
			<media:title type="html">UserName replace</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/4.png" medium="image">
			<media:title type="html">UserName replaced</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/7.png" medium="image">
			<media:title type="html">Generation information</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/8.png" medium="image">
			<media:title type="html">Generation information Patch</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/05/9.png" medium="image">
			<media:title type="html">Generation information Patched</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the Cache Sub-Producer</title>
		<link>http://blog.codefluententities.com/2013/04/24/using-the-cache-sub-producer/</link>
		<comments>http://blog.codefluententities.com/2013/04/24/using-the-cache-sub-producer/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 17:02:33 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[.NET Domain Model]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Producers]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3130</guid>
		<description><![CDATA[&#160; CodeFluent Entities provides an integrated cache system for the Business Object Model (BOM) layer.  The Object Model Cache (OMC) is not enabled by default. To add the cache feature to your BOM you need to first add a Cache sub producer. &#160; &#160; If you set the “Is Default Enable” attribute to “True” the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3130&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;<br />
CodeFluent Entities provides an integrated cache system for the Business Object Model (BOM) layer.  The <a title="The Object Model Cache" href="http://www.softfluent.com/documentation/webframe.html?BOM_Caching.html" target="_blank">Object Model Cache </a>(OMC) is not enabled by default. To add the cache feature to your BOM you need to first add a Cache sub producer.<br />
&nbsp;<br />
<div id="attachment_3131" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/04/cachesubproducer.png"><img class="size-full wp-image-3131" alt="The Cache Sub-Producer" src="http://codefluententities.files.wordpress.com/2013/04/cachesubproducer.png?w=595&#038;h=187" width="595" height="187" /></a><p class="wp-caption-text">The Cache Sub-Producer</p></div><br />
&nbsp;<br />
If you set the “Is Default Enable” attribute to “True” the cache feature will be enabled for all the entities in your model. You can also decide to enable or not the cache feature by entity or by method.<br />
&nbsp;<br />
<div id="attachment_3132" class="wp-caption aligncenter" style="width: 580px"><a href="http://codefluententities.files.wordpress.com/2013/04/enablecacheentity.png"><img class="size-full wp-image-3132" alt="Enable Cache on an Entity" src="http://codefluententities.files.wordpress.com/2013/04/enablecacheentity.png?w=595"   /></a><p class="wp-caption-text">Enable Cache on an Entity</p></div><br />
&nbsp;<br />
As you can see in the image above, you can independently specify whether you want to enable the cache feature for Collections or not by changing the value of the “Is Collection Enabled” attribute.<br />
&nbsp;<br />
If you enable the cache feature, when calling a “LoadXXX” method (ex. Load, LoadById…) on your entity will make that a cache verification is performed before trying to load the data from the data source (SQL server for example).<br />
&nbsp;<br />
If you want to bypass the cache you can call the “NoCacheLoadXXX” method (ex. NoCacheLoad, NoCacheLoadById…). When saving or deleting an instance of an entity, the cache is cleared (for that entity) and you can clear manually the cache calling the “CacheClear” method on an entity (public static method).<br />
&nbsp;<br />
You may considerate some points when using a Cache system:</p>
<ul>
<li>Complexity will be added to your application.</li>
<li>Unexpected behaviors may appear if not using it correctly.</li>
<li>The Object Model Cache provided by default is an in-memory cache, so it cannot be shared between servers.</li>
<li>It is not interesting to use a Cache system if the cached data changes too often. It&#8217;s best to cache immutable or almost immutable data.</li>
</ul>
<p>&nbsp;<br />
An example scenario when the Object Model Cache feature could be useful may be when storing “referential” data on a data base or data that does not change too often.<br />
&nbsp;<br />
CodeFluent entities provides three types of Cache implementations:</p>
<ul>
<li><b>Simple Cache Manager</b>, based on the ASP .NET cache (<a title="Using the ASP.NET Cache outside of ASP.NET" href="http://www.hanselman.com/blog/UsingTheASPNETCacheOutsideOfASPNET.aspx" target="_blank">that can be used outside of ASP.NET</a>)  (<em>CodeFluent.Runtime.Caching.SimpleCacheManager, CodeFluent.Runtime</em>).</li>
<li><b><a title="Working with both the cache sub producer and the localization aspect" href="http://blog.codefluententities.com/2012/12/27/working-with-both-the-cache-sub-producer-and-the-localization-aspect/" target="_blank">Simple Localized Cache Manager</a></b>, a sub-class of the Simple Cache Manager that can manage localized keys (<em>CodeFluent.Runtime.Caching.LocaleCacheManager, CodeFluent.Runtime</em>)</li>
<li><b>Enterprise Library Cache Management</b>, you must install the <a title="Enterprise Library" href="http://msdn.microsoft.com/en-us/library/cc467894.aspx" target="_blank">Enterprise Library</a> in order to use it (<em>CodeFluent.Runtime.Caching.EnterpriseLibraryCacheManager, CodeFluent.Runtime</em>).</li>
</ul>
<p>&nbsp;<br />
You can specify the type of cache you want to use on the “Runtime Cache Type Name” attribute (the full type name). You can use a different cache systems by scope (entity, method).<br />
&nbsp;<br />
<div id="attachment_3135" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/04/cachetype.png"><img class="size-full wp-image-3135" alt="Runtime Cache Type Name" src="http://codefluententities.files.wordpress.com/2013/04/cachetype.png?w=595&#038;h=341" width="595" height="341" /></a><p class="wp-caption-text">Runtime Cache Type Name</p></div><br />
&nbsp;</p>
<blockquote><p>You can use a different or custom type of cache not provided by CodeFluent Entities, you only need to implement the <em>CodeFluent.Runtime.Caching.ICacheManager</em> interface.</p></blockquote>
<p>&nbsp;</p>
<p>Finally, you can disable the cache feature by configuration (only for the Simple Cache Manager and the Simple Localized Cache Manager), for a testing or development environment for example. You only need to add the following code to your app.config or web.config file:<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
&lt;appSettings&gt;
   &lt;add key=&quot;CodeFluent.Runtime.Caching.SimpleCacheManager.Enabled&quot; value=&quot;false&quot;/&gt;
&lt;/appSettings&gt;
</pre>
<p>&nbsp;<br />
&nbsp;</p>
<p>Regards,<br />
&nbsp;<br />
Pablo Fernandez Duran<br />
&nbsp;<br />
&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3130/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3130&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/04/24/using-the-cache-sub-producer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/cachesubproducer.png" medium="image">
			<media:title type="html">The Cache Sub-Producer</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/enablecacheentity.png" medium="image">
			<media:title type="html">Enable Cache on an Entity</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/cachetype.png" medium="image">
			<media:title type="html">Runtime Cache Type Name</media:title>
		</media:content>
	</item>
		<item>
		<title>Remove the current date and time to generated files</title>
		<link>http://blog.codefluententities.com/2013/04/22/remove-the-current-date-and-time-to-generated-files/</link>
		<comments>http://blog.codefluententities.com/2013/04/22/remove-the-current-date-and-time-to-generated-files/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 12:11:20 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Producers]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[Diff Engine]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3117</guid>
		<description><![CDATA[&#160; &#160; CodeFluent Entities adds some information to generated files every time a code production is run. &#160; This information contains general information (for all producers) and specific information (for each producer): &#160; The CodeFluent Entities Build version. The current date and time. The Runtime version. The Target version. The Culture. The Encoding. - … [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3117&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;<br />
&nbsp;<br />
CodeFluent Entities adds some information to generated files every time a code production is run.<br />
&nbsp;<br />
This information contains general information (for all producers) and specific information (for each producer):<br />
&nbsp;</p>
<ul>
<li>The CodeFluent Entities Build version.</li>
<li>The current date and time.</li>
<li>The Runtime version.</li>
<li>The Target version.</li>
<li>The Culture.</li>
<li>The Encoding.</li>
<li>- …</li>
</ul>
<p>&nbsp;<br />
<div id="attachment_3120" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/04/generationinfos.png"><img class="size-full wp-image-3120" alt="Generation information" src="http://codefluententities.files.wordpress.com/2013/04/generationinfos.png?w=595&#038;h=256" width="595" height="256" /></a><p class="wp-caption-text">Generation information</p></div><br />
&nbsp;<br />
You might want to avoid CodeFluent Entities to add some of this information to generated code.<br />
&nbsp;<br />
For example, each time a code production is made almost all generated files will have a new “generation date” even if the generated code is the same.<br />
&nbsp;<br />
When using a source control system you will need to checkin/commit every single file even if  only the generation date has changed. This can lead to conflicts and unnecessary merges.</p>
<p>&nbsp;</p>
<div id="attachment_3119" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/04/diff.png"><img class="size-full wp-image-3119" alt="File Diff" src="http://codefluententities.files.wordpress.com/2013/04/diff.png?w=595&#038;h=142" width="595" height="142" /></a><p class="wp-caption-text">File Diff</p></div>
<p>&nbsp;</p>
<p>Well, CodeFluent Entities provides an option to remove the &#8220;generation date and time&#8221; when running producers.  <br />
This options is found in the &#8220;advanced properties tab&#8221; at the project level  (<i>right click on the CodeFluent Entities project &gt; Properties</i>).<br />
&nbsp;&nbsp;</p>
<blockquote><p>Set the <a title="Changing the Production Behavior" href="http://www.softfluent.com/documentation/ProducerConcepts_ChangingTheProductionBehavior.html" target="_blank"><strong>defaultProducerProductionFlag</strong> </a>flag to <strong>RemoveDiffs </strong>to avoid having the &#8220;date and time&#8221; on generated files.</p></blockquote>
<p>&nbsp;&nbsp;<br />
<div id="attachment_3123" class="wp-caption aligncenter" style="width: 605px"><a href="http://codefluententities.files.wordpress.com/2013/04/removediffs.png"><img class="size-full wp-image-3123" alt="Default Producer Production Flags" src="http://codefluententities.files.wordpress.com/2013/04/removediffs.png?w=595&#038;h=363" width="595" height="363" /></a><p class="wp-caption-text">Default Producer Production Flags</p></div></p>
<p>&nbsp;&nbsp;</p>
<blockquote><p>Since the CodeFluent Entities build 702 (march 2013) the RemoveDiffs production flag option now also removes the Runtime Version value added to generated files.</p></blockquote>
<p>&nbsp;&nbsp;&nbsp;</p>
<p>Regards,</p>
<p>Pablo Fernandez Duran</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3117&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/04/22/remove-the-current-date-and-time-to-generated-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/generationinfos.png" medium="image">
			<media:title type="html">Generation information</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/diff.png" medium="image">
			<media:title type="html">File Diff</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/removediffs.png" medium="image">
			<media:title type="html">Default Producer Production Flags</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the LINQ to SQL Sub-Producer</title>
		<link>http://blog.codefluententities.com/2013/04/17/using-the-linq-to-sql-sub-producer/</link>
		<comments>http://blog.codefluententities.com/2013/04/17/using-the-linq-to-sql-sub-producer/#comments</comments>
		<pubDate>Wed, 17 Apr 2013 13:02:21 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[Data access]]></category>
		<category><![CDATA[Developing Using CodeFluent Entities]]></category>
		<category><![CDATA[Producers]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Sub-Producer]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3091</guid>
		<description><![CDATA[&#160; CodeFluent Entities gives you the possibility to make your generated Business Object Model (BOM) compatible with the LINQ to SQL data access infrastructure. &#160; CodeFluent Entities ships a LINQ to SQL producer, that is in fact a Sub-Producer of the Business Object Model (BOM) Producer. &#160; Let&#8217;s start by setting a model to work [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3091&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;<br />
CodeFluent Entities gives you the possibility to make your generated Business Object Model (BOM) compatible with the <a title="LINQ to SQL: .NET Language-Integrated Query for Relational Data" href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" target="_blank">LINQ to SQL</a> data access infrastructure.<br />
&nbsp;<br />
CodeFluent Entities ships a LINQ to SQL producer, that is in fact a Sub-Producer of the Business Object Model (BOM) Producer.<br />
&nbsp;<br />
Let&#8217;s start by setting a model to work with.<br />
&nbsp;<br />
For this post I will create a very simple model. A &#8220;Person&#8221; entity who has zero or more &#8220;Pets&#8221; of a given kind.<br />
&nbsp;<br />
<div id="attachment_3103" class="wp-caption aligncenter" style="width: 880px"><img class="size-full wp-image-3103" alt="Pet management model" src="http://codefluententities.files.wordpress.com/2013/04/c.png?w=595"   /><p class="wp-caption-text">Pet management model</p></div><br />
&nbsp;<br />
I will also add Class Library project to my solution so I can store the generated code by CodeFluent Entities.<br />
&nbsp;<br />
I will add a Persistence producer (SQL Server) and a Business Object Model Producer. I will set the Target Directory to my Class Library project for both producers.<br />
&nbsp;<br />
Now I can add my Linq-To-Sql producer. As said before, this producer is a Sub-Producer of the BOM Producer, so I have to add it to the BOM Producer.<br />
&nbsp;<br />
<div id="attachment_3104" class="wp-caption aligncenter" style="width: 427px"><img class="size-full wp-image-3104" alt="Add Sub-Producer" src="http://codefluententities.files.wordpress.com/2013/04/a.png?w=595"   /><p class="wp-caption-text">Add Sub-Producer</p></div><br />
&nbsp;<br />
<div id="attachment_3105" class="wp-caption aligncenter" style="width: 865px"><img class="size-full wp-image-3105" alt="LINQ to SQL Sub-Producer" src="http://codefluententities.files.wordpress.com/2013/04/b.png?w=595"   /><p class="wp-caption-text">LINQ to SQL Sub-Producer</p></div><br />
&nbsp;<br />
As you can see, there is no configuration required for this Sub-Producer.<br />
&nbsp;<br />
We need to set the &#8220;Default Entity Tracking Mode&#8221; to &#8220;None&#8221; at the project level to avoid any problem with the LINQ to SQL query provider.<br />
&nbsp;<br />
<div id="attachment_3108" class="wp-caption aligncenter" style="width: 401px"><img class="size-full wp-image-3108" alt="Default Entity Tracking Modes" src="http://codefluententities.files.wordpress.com/2013/04/f.png?w=595"   /><p class="wp-caption-text">Default Entity Tracking Modes</p></div><br />
&nbsp;<br />
Let&#8217;s build our CodeFluent Entities project, and open a BOM class so we can see what has been generated.<br />
&nbsp;<br />
<div id="attachment_3106" class="wp-caption aligncenter" style="width: 926px"><img class="size-full wp-image-3106" alt="LINQ to SQL attributes" src="http://codefluententities.files.wordpress.com/2013/04/d.png?w=595"   /><p class="wp-caption-text">LINQ to SQL attributes</p></div><br />
&nbsp;<br />
We now see that our class has been decorated with LINQ to SQL attributes. We also see that the &#8220;System.Data.Linq&#8221; namespace is not defined. To fix that we need to add a reference to the &#8220;<a title="System.Data.Linq Namespace" href="http://msdn.microsoft.com/en-us/library/system.data.linq.aspx" target="_blank">System.Data.Linq</a>&#8221; assembly in our BOM project.<br />
&nbsp;<br />
We have now a LINQ to SQL compliant BOM.<br />
&nbsp;<br />
Let&#8217;s test it using LINQ to SQL.<br />
&nbsp;<br />
For that I will add a simple Console application. Then I add a reference to my BOM project, to the CodeFluent.Runtime assembly and to the System.Data.Linq assembly. And add the right <a title="BOM Application Configuration" href="http://www.softfluent.com/documentation/webframe.html?BOM_ApplicationConfiguration.html" target="_blank">application configuration</a>.<br />
&nbsp;<br />
We will use the <a title="DataContext Class" href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx" target="_blank">DataContext</a> class provided by the LINQ to SQL infrastructure to manipulate data (insert, delete, update and read). And we can retrieve the connection string from the CodeFluentContext class.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
string connectionString = CodeFluentContext.Get(PetsManagement.Constants.PetsManagementStoreName).Persistence.ConnectionString;
using (DataContext context = new DataContext(connectionString))
{
}
</pre>
<p>&nbsp;<br />
Let&#8217;s start by adding some data to our database:<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
string connectionString = CodeFluentContext.Get(PetsManagement.Constants.PetsManagementStoreName).Persistence.ConnectionString;
using (DataContext context = new DataContext(connectionString))
{

    Person bart = new Person { Name = &quot;Bart&quot; };
    Pet bartsDog = new Pet { Name = &quot;Santa's Little Helper&quot;, Age = 2, Kind = PetKind.Dog };
    bartsDog.Owner = bart;
    Pet bartsCat = new Pet { Name = &quot;Snowball II&quot;, Age = 3, Kind = PetKind.Cat };
    bartsCat.Owner = bart;//not true, is Lisa

    Person pablo = new Person { Name = &quot;Pablo&quot; };
    Pet pablosDog = new Pet { Name = &quot;Shiny&quot;, Age = 17, Kind = PetKind.Dog };
    pablosDog.Owner = pablo;
    Pet pablosDog2 = new Pet { Name = &quot;Vanilla&quot;, Age = 10, Kind = PetKind.Dog };
    pablosDog2.Owner = pablo;

    Person ferb = new Person { Name = &quot;Ferb&quot; };
    Pet ferbsPet = new Pet { Name = &quot;Perry&quot;, Age = 32, Kind = PetKind.Platypus };
    ferbsPet.Owner = ferb;

    context.GetTable&lt;Person&gt;().InsertAllOnSubmit(new[] { bart, pablo, ferb });
    context.GetTable&lt;Pet&gt;().InsertAllOnSubmit(new[] { bartsDog, bartsCat, pablosDog, pablosDog2, ferbsPet });

    context.SubmitChanges();
}
</pre>
<p>&nbsp;<br />
Now let&#8217;s retrieve all the pets grouped by &#8220;Pet kind&#8221;.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
string connectionString = CodeFluentContext.Get(PetsManagement.Constants.PetsManagementStoreName).Persistence.ConnectionString;
using (DataContext context = new DataContext(connectionString))
{
    var petsByKind = from pet in context.GetTable&lt;Pet&gt;()
                        group pet by pet.Kind into gr
                        select gr;

    foreach (IGrouping&lt;PetKind, Pet&gt; kindGroup in petsByKind)
    {
        Console.WriteLine(&quot;----&quot; + kindGroup.Key + &quot;----&quot;);
        foreach (Pet pet in kindGroup)
        {
            Console.WriteLine(pet.Name + &quot; : &quot; + pet.Owner.Name);
        }
    }
}
</pre>
<p>&nbsp;<br />
The result is:</p>
<p><div id="attachment_3107" class="wp-caption aligncenter" style="width: 283px"><img class=" wp-image-3107 " alt="Pets grouped by kind" src="http://codefluententities.files.wordpress.com/2013/04/e.png?w=273&#038;h=164" width="273" height="164" /><p class="wp-caption-text">Pets grouped by kind</p></div><br />
&nbsp;<br />
Let&#8217;s now delete a cat named &#8220;Snowball II&#8221; which owners name is &#8220;Bart&#8221;.<br />
&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
string connectionString = CodeFluentContext.Get(PetsManagement.Constants.PetsManagementStoreName).Persistence.ConnectionString;
using (DataContext context = new DataContext(connectionString))
{
    Pet petToDelete = (
                        from person in context.GetTable&lt;Person&gt;()
                        where
                            person.Name == &quot;Bart&quot;
                        from pet in person.Pets
                        where
                            pet.Kind == PetKind.Cat &amp;&amp;
                            pet.Name == &quot;Snowball II&quot;
                        select pet
                        )
                        .FirstOrDefault();

    if (petToDelete != null)
    {
        context.GetTable&lt;Pet&gt;().DeleteOnSubmit(petToDelete);
        context.SubmitChanges();
    }

}
</pre>
<p>&nbsp;<br />
Thanks to the LINQ to SQL Sub-Producer we can use the LINQ to SQL infrastructure with our BOM, but there are several limitations and several concepts/features that can be done by CodeFluent Entities and not supported by LINQ to SQL: The CodeFluent Entities model is richer than LINQ to SQL (rules, validation, aspects, advanced relations, automatic tracking, cache, circular dependencies, multi-databases&#8230;).<br />
&nbsp;&nbsp;</p>
<p>Regards,<br />
Pablo Fernandez Duran</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3091/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3091&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/04/17/using-the-linq-to-sql-sub-producer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/c.png" medium="image">
			<media:title type="html">Pet management model</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/a.png" medium="image">
			<media:title type="html">Add Sub-Producer</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/b.png" medium="image">
			<media:title type="html">LINQ to SQL Sub-Producer</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/f.png" medium="image">
			<media:title type="html">Default Entity Tracking Modes</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/d.png" medium="image">
			<media:title type="html">LINQ to SQL attributes</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/e.png" medium="image">
			<media:title type="html">Pets grouped by kind</media:title>
		</media:content>
	</item>
		<item>
		<title>CodeFluent Entities and Syncfusion for an amazing application!</title>
		<link>http://blog.codefluententities.com/2013/04/15/codefluent-entities-and-syncfusion-for-an-amazing-application/</link>
		<comments>http://blog.codefluententities.com/2013/04/15/codefluent-entities-and-syncfusion-for-an-amazing-application/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 10:11:20 +0000</pubDate>
		<dc:creator>SoftFluent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[CodeFluent Entities]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Model-First]]></category>
		<category><![CDATA[Partnership]]></category>
		<category><![CDATA[Software industrialization]]></category>
		<category><![CDATA[Syncfusion]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://blog.codefluententities.com/?p=3066</guid>
		<description><![CDATA[When applications are beautiful, fast and robust at the same time, we qualify them as amazing. If you think it also means a long development process, then you have not seen applications using both SoftFluent and Syncfusion products altogether! SoftFluent and Syncfusion have partnered to help you build these amazing applications in no time.  CodeFluent [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3066&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When applications are beautiful, fast and robust at the same time, we qualify them as amazing. If you think it also means a long development process, then you have not seen applications using both SoftFluent and Syncfusion products altogether!</p>
<p>SoftFluent and Syncfusion have partnered to help you build these amazing applications in no time.  CodeFluent makes the application highly functional, while Syncfusion makes the application interface elegant and user-friendly.</p>
<p>CodeFluent Entities is a unique product integrated into Visual Studio which allows developers to generate database scripts, code, web services and UIs in the Microsoft .NET platform. The code generation process is model-first and continuous: from your declarative model, a meta-model will be inferred which code generators will then translate into code. Over 20 code generators (a.k.a. <i>producers’</i>) are provided out of the box and can be combined to create your own application following your desired architecture, using your desired technologies.</p>
<p>Syncfusion, Inc. provides the broadest range of enterprise-class software components and tools for the Microsoft .NET platform. With Syncfusion, developers can move beyond simply coding applications to delivering real business innovation—the elegant user interfaces, business intelligence dashboards, and sophisticated reporting that today&#8217;s business users need, in the formats they demand.</p>
<p>Whether you need to build applications with WinForms or WPF, or websiteswith WebForms or MVC, SoftFluent and Syncfusion provide all the necessary tools to help you.</p>
<p>To show you how it works, we built a full application using CodeFluent Entities and Syncfusion components. With Visual Studio 2012, we have created a WPF application that consumes web services to communicate with an SQL Server 2008 database. The database we used is a sample database of Microsoft SQL Server, called <i>AdventureWorks</i>.</p>
<p style="color:#fff;">.</p>
<p>The application can be created in five steps:</p>
<p style="color:#fff;">.</p>
<p><b>1. CodeFluent Entities project</b></p>
<p>Create a CodeFluent Entities project in Visual Studio 2012. You also need a class library project that contains the business-object model, a class library project (Proxy) that contains your web service contracts, and the WPF application.</p>
<p style="color:#fff;">.</p>
<p><b>2. Import the <i>AdventureWorks</i> database</b></p>
<p>If you right-click on the CodeFluent Entities project, you will have the option to import an existing database or model as you can see on the screenshot below.</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/04/15.png"><img class="aligncenter size-full wp-image-3069" alt="1" src="http://codefluententities.files.wordpress.com/2013/04/15.png?w=595"   /></a></p>
<div>
<p>Then follow the instructions to import the <i>AdventureWorks</i> database.</p>
<p style="color:#fff;">.</p>
<p><b>3. Set up the producers</b></p>
<p>Once the database has been imported, you can view the visual model inside the CodeFluent Entities project (Surface &gt; Default) as you can see here:</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/04/24.png"><img class="aligncenter size-full wp-image-3070" alt="2" src="http://codefluententities.files.wordpress.com/2013/04/24.png?w=595&#038;h=535" width="595" height="535" /></a></p>
<p>Now that you have your model, you need to add producers. These producers are responsible for generating code for your application.</p>
<p>The first producer is the <i>BOM</i> (Business Object Model) producer, which corresponds to the business logic. The code generated will be classes for each entity of your model. This code is exceptionally readable and can be customized using partial classes, if needed. Also, this producer contains a sub- producer responsible for generating services.</p>
<p>The second producer is the <i>SQL</i> producer responsible for generating SQL scripts, such as tables, views, and stored procedures.</p>
<p>The third producer is the <i>WPF ClickOnce Smart Client</i>, which is responsible for generating UIs. These UIs are generated using templates, located in the CodeFluent Folder. We will discuss this in more detail later.</p>
<p>The fourth producer is the <i>Template</i>, responsible for creating a host for the web services.</p>
<p>The fifth producer is the <i>Command Line Execution</i> producer, responsible for running a batch file that will insert data in your database.</p>
<div><a href="http://codefluententities.files.wordpress.com/2013/04/34.png"><img class="aligncenter size-full wp-image-3071" alt="3" src="http://codefluententities.files.wordpress.com/2013/04/34.png?w=595"   /></a></div>
<div></div>
<div>
<p style="color:#fff;">.</p>
<p><b>4. Generation</b></p>
<p>The model is ready to be generated. In a single click, the CodeFluent Entities project will load your model in memory, and run each of the producers to generate ASP.NET code (C# in this example), SQL scripts and WPF controls. The application is almost ready to run. The last steps are to:</p>
<ol>
<li>Set up the connection string in your WPF application.</li>
<li>Set up the application that hosts the web services to run at the same time as the WPF application.</li>
</ol>
<p>That is all you need to do in order to run the application! When you launch the application, you will have a list of all entities, and you will be able to manipulate the data of these entities with generic methods such as <i>load</i>, <i>load</i> <i>all</i>, <i>update</i>, <i>delete,</i> and <i>save</i>. Each of these actions will consume the web services that are being hosted in the other application.</p>
<p style="color:#fff;">.</p>
<p><b>5. SyncFusion Components</b></p>
<p>The full running application uses standard ASP.NET controls for your WPF application. Though these components are functional, they are not always the best-looking ones. This is where Syncfusion comes in to transform a functional application into an amazing application.</p>
<p>CodeFluent Entities generates reusable controls for the application, so that one control can be used in several pages. As a result, the work consists in updating these ASP.NET standards controls by using Syncfusion controls, to end up with a highly functional and beautiful application:</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/04/44.png"><img class="aligncenter size-full wp-image-3072" alt="4" src="http://codefluententities.files.wordpress.com/2013/04/44.png?w=595&#038;h=451" width="595" height="451" /></a></p>
<p align="center"><i>Interface displaying the list of departments</i></p>
<p style="color:#fff;">.</p>
<p><a href="http://codefluententities.files.wordpress.com/2013/04/53.png"><img class="aligncenter size-full wp-image-3073" alt="5" src="http://codefluententities.files.wordpress.com/2013/04/53.png?w=595&#038;h=452" width="595" height="452" /></a></p>
<p align="center"><i>Interface displaying the edition of a department in a popup</i></p>
<p style="color:#fff;">.</p>
<p align="center"><a href="http://codefluententities.files.wordpress.com/2013/04/63.png"><img class="aligncenter size-full wp-image-3074" alt="6" src="http://codefluententities.files.wordpress.com/2013/04/63.png?w=595&#038;h=480" width="595" height="480" /></a></p>
<p align="center"><i>Interface displaying the edition of the SalesTerritory field that corresponds to a list prefilled with a related entity</i></p>
<p style="color:#fff;">.</p>
<div>
<p>Using the power of CodeFluent Entities to generate functional applications quickly, and the power of Syncfusion’s beautiful components, you can create amazing applications in no time.</p>
<p style="color:#fff;">.</p>
<p><b>6. Unlimited possibilities</b></p>
<p>To go further with CodeFluent Entities and Syncfusion integration, you can reuse Syncfusion components in other applications at no cost. Indeed, CodeFluent Entities uses templates to generate components, such as the view page, the edit form and so on. These templates are available in the CodeFluent folder (where it was installed, usually in \CodeFluent\Modeler\Templates\SmartClient).</p>
<p>Extremely simple to read and to understand, these templates can be modified to produce pages with custom components, such as the ones provided by Syncfusion. By doing so, each CodeFluent Entities project can reuse these templates to produce amazing applications. Although you have developed a WPF application in this example, you can do the same with all other types of applications, such as WinForms, WebForms, MVC, mobile or any combination of these technologies.</p>
<p style="color:#fff;">.</p>
<p><em>If you want to download the sample project demo please click here:</em> <a href="http://www.softfluent.com/downloads/AdventureWorksReloaded.zip">http://www.softfluent.com/downloads/AdventureWorksReloaded.zip</a></p>
</div>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codefluententities.wordpress.com/3066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codefluententities.wordpress.com/3066/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.codefluententities.com&#038;blog=12622208&#038;post=3066&#038;subd=codefluententities&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.codefluententities.com/2013/04/15/codefluent-entities-and-syncfusion-for-an-amazing-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1edca82ee7e430421a86ff23d26a3d97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">softfluent</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/15.png" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/24.png" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/34.png" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/44.png" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/53.png" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://codefluententities.files.wordpress.com/2013/04/63.png" medium="image">
			<media:title type="html">6</media:title>
		</media:content>
	</item>
	</channel>
</rss>
