<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel xmlns:blog="http://www.dotnetnuke.com/blog/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
    <title>Switching the Lights</title>
    <description>Sharing the Lights</description>
    <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/BlogId/3/Default.aspx</link>
    <language>en-US</language>
    <webMaster />
    <pubDate>Sun, 15 Mar 2026 08:13:07 GMT</pubDate>
    <lastBuildDate>Sun, 15 Mar 2026 08:13:07 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 4.0.0.0</generator>
    <item>
      <title>Can I delete this?</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/175/Can-I-delete-this.aspx</link>
      <description>&lt;p&gt;In a &lt;a href="http://kostaschristodoulou.blogspot.gr/2012/06/simple-extension-methods-part-2.html" target="_blank"&gt;previous post&lt;/a&gt; I suggested a way to override default LightSwitch add/edit behavior. In this post I will suggest an override to default delete behavior.&lt;/p&gt;  &lt;p&gt;It has happened many times to delete entries, only to get an error message, when trying to save, informing me about reference constraints being violated and the action cannot be completed. This is not much of problem when you try to delete one record (apart from the fact this message is ugly and not one that I would allow my end users to deal with, for that matter). But when trying to delete many records you have no clue which was the one (or more) record(s) that cannot be deleted. In this case all you can do is delete-save until you find the record that cannot be deleted. And when you find it, you have to refresh your screen or undo the changes of the current record (a future article will suggest a way to do this).&lt;/p&gt;  &lt;p&gt;What I needed was a good generic way to be able to set &lt;em&gt;Delete_CanExecute &lt;/em&gt;result. This is my suggestion using (what else) extension methods, interfaces (Yann will love me for this &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/175/Windows-Live-Writer-73b0ea34fb04_C65C-wlEmoticon-smile_2.png" /&gt;) and an attribute.&lt;/p&gt;  &lt;p&gt;First the interface to help decide if an instance can be deleted or not:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IDependencyCheck : IEntityObject
{
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanDelete { get; }
}&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;Quite simple you must admit. Keep in mind interfaces you want to use in your common project have to be accessible both by Server and Client project also. If someone here thinks of &lt;em&gt;EntityName_CanDelete&lt;/em&gt;, someone forgets that it is a server side hook.&lt;/p&gt;

&lt;p&gt;Now an attribute to help us decide which of the dependencies an entity might have are strong ones, meaning that the referential integrity of the database or your business logic if you don’t use database constraints, would not allow an instance to be deleted.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[AttributeUsage(AttributeTargets.Class)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StrongDependencyAttribute : Attribute
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; StrongDependencyAttribute(&lt;span class="kwrd"&gt;string&lt;/span&gt; dependencies) {
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.dependencies = dependencies.ToStringArray();
  }

  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] Dependencies {
    get { &lt;span class="kwrd"&gt;return&lt;/span&gt; dependencies; }
  }

  &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] dependencies;
}
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;/pre&gt;

&lt;p&gt;This attribute takes a list of strong reference property names as comma delimited string (or whatever delimiter you like for that matter) using these simple extensions:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] ToStringArray(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; strings) {
   &lt;span class="kwrd"&gt;return&lt;/span&gt; strings.ToStringArray(&lt;span class="str"&gt;','&lt;/span&gt;);
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] ToStringArray(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; strings, &lt;span class="kwrd"&gt;char&lt;/span&gt; delimiter) {
   &lt;span class="kwrd"&gt;return&lt;/span&gt; (from &lt;span class="kwrd"&gt;string&lt;/span&gt; item &lt;span class="kwrd"&gt;in&lt;/span&gt; strings.Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] { delimiter }, StringSplitOptions.RemoveEmptyEntries)
               select item.Trim()).ToArray();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If you want to use another delimiter just replace &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.dependencies = dependencies.ToStringArray();&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;in the constructor with (for example):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.dependencies = dependencies.ToStringArray(&lt;span class="str"&gt;';'&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Or if you want, you can have one instance of the attribute for each property you want to check and avoid delimited strings altogether. Plenty of choices…&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/175/Windows-Live-Writer-73b0ea34fb04_C65C-wlEmoticon-smile_2.png" /&gt;.&lt;/p&gt;

&lt;p&gt;Keep in mind that if you declare no instance of this attribute but you implement &lt;strong&gt;IDependencyCheck&lt;/strong&gt; then ALL dependencies will be considered as strong ones and checked for integrity. &lt;/p&gt;

&lt;p&gt;This attribute needs to be accessible by the Common project only.&lt;/p&gt;

&lt;p&gt;Now, all that said, there are two extension methods that will help us do the job.&lt;/p&gt;

&lt;p&gt;The first one needs to be accessible by the Client project only:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanDeleteSelection(&lt;span class="kwrd"&gt;this&lt;/span&gt; IScreenObject screen, &lt;span class="kwrd"&gt;string&lt;/span&gt; collectionName) {
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (!screen.HasSelection(collectionName))
     &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
   IVisualCollection collection = screen.Details.Properties[collectionName].Value &lt;span class="kwrd"&gt;as&lt;/span&gt; IVisualCollection;
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (collection.SelectedItem &lt;span class="kwrd"&gt;is&lt;/span&gt; IDependencyCheck)
     &lt;span class="kwrd"&gt;return&lt;/span&gt; (collection.SelectedItem &lt;span class="kwrd"&gt;as&lt;/span&gt; IDependencyCheck).CanDelete;
   &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Please note I am using IScreenObject.HasSelection extension that has already been introduced in a &lt;a href="http://kostaschristodoulou.blogspot.gr/2012/06/simple-extension-methods-part-2.html" target="_blank"&gt;previous post&lt;/a&gt;. That’s why I am not checking if the cast to IVisualCollection is successful (not null).&lt;/p&gt;

&lt;p&gt;The second one has to be accessible by the Common project only:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanDelete(&lt;span class="kwrd"&gt;this&lt;/span&gt; IEntityObject entity) {
      IEnumerable&lt;IEntityCollectionProperty&gt; collectionProperties = 
        entity.Details.Properties.All()
        .Where(p =&gt; p.GetType().GetInterfaces()
          .Where(t =&gt; t.Name.Equals(&lt;span class="str"&gt;"IEntityCollectionProperty"&lt;/span&gt;))
          .FirstOrDefault() != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        .Cast&lt;IEntityCollectionProperty&gt;();
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (collectionProperties == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
      List&lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&gt; strongDependencies = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&gt;();
      IEnumerable&lt;StrongDependencyAttribute&gt; dependencies = 
        entity.GetType()
        .GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(StrongDependencyAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;)
        .Cast&lt;StrongDependencyAttribute&gt;();
      &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (StrongDependencyAttribute dependency &lt;span class="kwrd"&gt;in&lt;/span&gt; dependencies)
        strongDependencies.AddRange(dependency.Dependencies);
      &lt;span class="kwrd"&gt;bool&lt;/span&gt; hasDependencies = strongDependencies.FirstOrDefault() != &lt;span class="kwrd"&gt;null&lt;/span&gt;;
      &lt;span class="kwrd"&gt;bool&lt;/span&gt; canDelete = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
      &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (IEntityCollectionProperty property &lt;span class="kwrd"&gt;in&lt;/span&gt; collectionProperties) {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (hasDependencies &amp;&amp;strongDependencies.FirstOrDefault(d =&gt; d.Equals(property.Name)) == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
          &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
        IEnumerable &lt;span class="kwrd"&gt;value&lt;/span&gt; = entity.GetType()
          .GetProperty(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0}Query"&lt;/span&gt;, property.Name))
          .GetValue(entity, &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; IEnumerable;
        &lt;span class="kwrd"&gt;try&lt;/span&gt; {
          &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt; != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;&amp; &lt;span class="kwrd"&gt;value&lt;/span&gt;.GetEnumerator().MoveNext()) {
            canDelete = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
          }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; {
          &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
        }
      }
      &lt;span class="kwrd"&gt;return&lt;/span&gt; canDelete;
    }&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;Although it’s obvious at first glance what the code does &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-hotsmile" alt="Hot smile" src="/Portals/0/Blog/Files/3/175/Windows-Live-Writer-73b0ea34fb04_C65C-wlEmoticon-hotsmile_2.png" /&gt;, I will give brief explanation:&lt;/p&gt;

&lt;p&gt;If there is not a &lt;strong&gt;StrongDependencyAtttibute&lt;/strong&gt; defined for the entity then all reference properties are checked and if at least one has members then the entity cannot be deleted. If a &lt;strong&gt;StrongDependencyAtttibute&lt;/strong&gt; is defined for the entity then only reference properties included in the attribute are checked. That’s all…&lt;/p&gt;

&lt;p&gt;If you manage to read the code (I am not very proud about the absence of comments) you will notice that only one-to-many and many-to-many references are handled. In my world one-to-one references mean inheritance and in this case both objects should be deleted. But what if the base object can be deleted (has no direct references) and the derived object has? Again in my world, if you are trying to delete the base object you are already doing it wrong! Anyway if someone lives in a world other than mine (I am very democratic guy &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-berightback" alt="Be right back" src="/Portals/0/Blog/Files/3/175/Windows-Live-Writer-73b0ea34fb04_C65C-wlEmoticon-berightback_2.png" /&gt;) and wants to support one-to-one relations all he/she has to do is find where &lt;strong&gt;IEntityCollectionProperty &lt;/strong&gt;definition is and look for the respective property type (I believe it is &lt;strong&gt;IEntityReferenceProperty &lt;/strong&gt;but I am not quite sure).&lt;/p&gt;

&lt;p&gt;And for the end an example so that anyone can see what all of the above end up to:&lt;/p&gt;

&lt;p&gt;Suppose you have a &lt;strong&gt;Customer&lt;/strong&gt; entity. And this Customer entity has a collection of &lt;strong&gt;Orders&lt;/strong&gt;. The property of the &lt;strong&gt;Customer&lt;/strong&gt; entity that holds these orders is called &lt;strong&gt;CustomerOrders&lt;/strong&gt;. In your Datasource you right-click &lt;strong&gt;Customer&lt;/strong&gt; entity and select &lt;strong&gt;View Table Code&lt;/strong&gt;. A partial class implementation file is created (if it does not already exist). Modify the definition of you class as follows:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[StrongDependency(&lt;span class="str"&gt;"CustomerOrders"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Customer : IDependencyCheck {
...

  &lt;span class="preproc"&gt;#region&lt;/span&gt; IDependencyCheck members 
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanDelete {
    get { &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.CanDelete(); }
  }
  &lt;span class="preproc"&gt;#endregion&lt;/span&gt; IDependencyCheck members
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Remember to reference (using) the namespace where your extension method (&lt;strong&gt;CanDelete)&lt;/strong&gt; is declared.&lt;/p&gt;

&lt;p&gt;Please note that &lt;strong&gt;IDependencyCheck&lt;/strong&gt; gives you the potential to write whatever else hardcoded (or not) check you want in your &lt;strong&gt;CanDelete&lt;/strong&gt; property implementation. In the code above I just call the extension method I introduced earlier. But you can do whatever you want. You can even skip the dependencies mechanism suggested altogether. The client side extension will still work.&lt;/p&gt;

&lt;p&gt;So in the screen that you have your list of Customers right click the &lt;strong&gt;Delete&lt;/strong&gt; command of the list or grid and in the &lt;strong&gt;&lt;em&gt;CustomersDelete_CanExecute &lt;/em&gt;&lt;/strong&gt;just write:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CustomersDelete_CanExecute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; result){
  result = &lt;span class="kwrd"&gt;this&lt;/span&gt;.CanDeleteSelection(&lt;span class="str"&gt;"Customers"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;As partial implementation of Execute write:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CustomersDelete_Execute(){
  &lt;span class="kwrd"&gt;this&lt;/span&gt;.Customers.DeleteSelected();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;I know some of you have already noticed the overhead of potentially loading the dependent objects the first time you select an item of your list or grid. I cannot argue with that, except for the fact that my approach is suggested for intranet implementations (I am not sure I would do something like that over the web) and the fact that the time under these circumstances is an acceptable price to pay in order to avoid the annoying referential integrity message. At least in my world &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/175/Windows-Live-Writer-73b0ea34fb04_C65C-wlEmoticon-smile_2.png" /&gt;.  &lt;/p&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/175/Can-I-delete-this.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/175/Can-I-delete-this.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/175/Can-I-delete-this.aspx</guid>
      <pubDate>Wed, 06 Feb 2013 07:19:30 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=175</trackback:ping>
    </item>
    <item>
      <title>De-fault Screens</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/158/De-fault-Screens.aspx</link>
      <description>&lt;p&gt;If you have tried implementing something that required a mechanism more complex than the default one provided by LightSwitch regarding default screen selection, you already are familiar with the limitations.&lt;/p&gt;
&lt;p&gt;For the ones that don’t get what I mean, a very common example is open the details screen of an object from a list containing items from a view (database view) that include the id of the original object. Imagine you have a &lt;strong&gt;Customer&lt;/strong&gt; entity and a &lt;strong&gt;CustomerInfo&lt;/strong&gt; entity that comes from a database view bringing aggregated data of the customer from various tables. Selecting and editing the &lt;strong&gt;CustomerInfo&lt;/strong&gt; you want to edit the &lt;strong&gt;Customer &lt;/strong&gt;not the &lt;strong&gt;CustomerInfo.&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;The above is only one fast example. Another would be having Add/Edit Screens i.e. screens that can handle both create or edit an existing object. In any case if you need to modify the default signature of a default screen (adding an extra parameter for example) causes this screen to be unselected as default screen because LightSwitch mechanism for default screens cannot handle it.&lt;/p&gt;
&lt;p&gt;Going back to the &lt;strong&gt;Customer/CustomerInfo&lt;/strong&gt; example, I have come across at least a couple of posts in threads trying to find a way to “override” the default click behavior of links in collections. In our example clicking on the link of the customer’s name (for example) will open a default screen for &lt;strong&gt;CustomerInfo&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;So, one easy solution is creating a default screen for &lt;strong&gt;CustomerInfo&lt;/strong&gt; where upon load you will open the &lt;strong&gt;Customers &lt;/strong&gt;default screen passing the id of the customer and close the current one. But how do you handle allowing only one instance of a details screen per object? Or all other issues that might come come up? (Imagine you have more than one view entities for the &lt;strong&gt;Customer &lt;/strong&gt;entity).&lt;/p&gt;
&lt;p&gt;Anyway, this is my approach at solving this issue, that works fine for me in a big project whose development runs for almost a year now (and by the way is the reason for not posting very often –understatement of the year- here lately):&lt;/p&gt;
&lt;p&gt;Reintroducing the &lt;strong&gt;ShowDefaultScreen&lt;/strong&gt; method of the &lt;strong&gt;Application&lt;/strong&gt; in the &lt;strong&gt;Client &lt;/strong&gt;project along with an interface defined and implemented by all screens that need to be involved.&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;This is the interface definition: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IDefaultScreen : IScreenObject
{
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; Shows(IEntityObject instance);
    IEntityObject Object { get; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, "Courier New", courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;ul&gt;
    &lt;li&gt;This is the code in Application.cs: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ShowDefaultScreen(IEntityObject instance) {
      &lt;span class="kwrd"&gt;this&lt;/span&gt;.ShowOrFocusDefaultScreen(instance);
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ShowOrFocusDefaultScreen(IEntityObject entity) {
  &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (IActiveScreen activeScreen &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.ActiveScreens) {
    &lt;span class="kwrd"&gt;if&lt;/span&gt; ((activeScreen.Screen &lt;span class="kwrd"&gt;is&lt;/span&gt; IDefaultScreen) &amp;&amp;&lt;br /&gt;        (activeScreen.Screen &lt;span class="kwrd"&gt;as&lt;/span&gt; IDefaultScreen).Shows(entity)) {
          activeScreen.Activate();
          &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }
      }
  entity.Details.Dispatcher.BeginInvoke(() =&gt; {
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!HandleEntityDefaultScreen(entity))
      &lt;span class="kwrd"&gt;base&lt;/span&gt;.ShowDefaultScreen(entity);
  });
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; HandleEntityDefaultScreen(IEntityObject entity) {
  &lt;span class="kwrd"&gt;switch&lt;/span&gt; (entity.GetType().Name) {
    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;"CustomerInfo"&lt;/span&gt;: {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.ShowEditCustomer((entity &lt;span class="kwrd"&gt;as&lt;/span&gt; CustomerInfo).Id);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
      }
      .
      .
      .
  }
  &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
}

&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial;"&gt;In the code displayed above the implementation in &lt;strong&gt;HandleEntityDefaultScreen &lt;/strong&gt;code is just to demonstrate the concept. The ellipsis below the first &lt;strong&gt;case&lt;/strong&gt; implies you can write whatever is required by your application.&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
    &lt;li&gt;
    &lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial;"&gt;And finally this is the code from the &lt;strong&gt;Customer &lt;/strong&gt;details screen that implements &lt;strong&gt;IDefaultScreen:&lt;/strong&gt;&lt;/span&gt;&lt;/pre&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EditCustomer : IDefaultScreen
{
   .
   .
   .
  &lt;span class="preproc"&gt;#region&lt;/span&gt; IDefaultScreen Members
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Shows(IEntityObject instance) {
    &lt;span class="kwrd"&gt;return&lt;/span&gt; (instance &lt;span class="kwrd"&gt;is&lt;/span&gt; CustomerInfo) &amp;&amp;&lt;br /&gt;           (instance &lt;span class="kwrd"&gt;as&lt;/span&gt; CustomerInfo).Id.Equals(&lt;span class="kwrd"&gt;this&lt;/span&gt;.CustomerProperty.Id);
  }

  &lt;span class="kwrd"&gt;public&lt;/span&gt; IEntityObject Object {
    get { &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.CustomerProperty; }
  }
  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, "Courier New", courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;style type="text/css"&gt;
    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, "Courier New", courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p &gt;
The careful reader will notice that the &lt;strong&gt;IEntityObject Object { get; } &lt;/strong&gt;property exposed by &lt;strong&gt;IDefaultScreen&lt;/strong&gt; is not used in the sample code. I ported the code exactly as I use it in my projects (apart from the changes made to demonstrate the &lt;strong&gt;Customer/CustomerInfo&lt;/strong&gt; paradigm) where this property is used for a different purpose. You can either remove it or find a good use for it &lt;img style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="/Portals/0/Blog/Files/3/158/Windows-Live-Writer-a7137360b1ab_8BD9-wlEmoticon-winkingsmile_2.png" /&gt;.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/158/De-fault-Screens.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/158/De-fault-Screens.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/158/De-fault-Screens.aspx</guid>
      <pubDate>Tue, 06 Nov 2012 22:00:00 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=158</trackback:ping>
    </item>
    <item>
      <title>Just Visiting or (not so) Simple Extension Methods (part 4)</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/152/Just-Visiting-or-not-so-Simple-Extension-Methods-part-4.aspx</link>
      <description>&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;One of my favorite design patterns since the age of c++ is the &lt;strong&gt;Visitor Pattern&lt;/strong&gt;. I will not explain here what the &lt;a href="http://www.oodesign.com/visitor-pattern.html" target="_blank"&gt;visitor pattern&lt;/a&gt; is. But, if you know how to use the design pattern this is a post worth reading.     &lt;br /&gt;One may ask what the visitor pattern has to do with LightSwitch. Well, it doesn’t! I mean not exclusively. But the code below provides a full visitor pattern implementation background that can also be used in LS. Also, a part of the implementation is ideal for LS, since one of the challenges I had to face, when trying to widely use the visitor pattern, was make it work for “sealed” classes, classes that were not written by me and could not easily fit to my –reflection based- visitor pattern implementation. To solve this the best thing I could think of was “wrapping”. And working with LS, most of the classes (apart from the ones that belong to the domain/datasource) are actually “sealed” in the way described above.(I have to note here that this reflection-based implementation is a revision of an implementation I found (if I recall correct) in CodeProject).     &lt;br /&gt;First the two basic interfaces that have to be defined:     &lt;br /&gt;The &lt;strong&gt;IVisitor&lt;/strong&gt; interface that has to be implemented by the “worker” (or helper to follow the VB-oriented naming of the LS Team &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sarcasticsmile" alt="Sarcastic smile" src="/Portals/0/Blog/Files/3/152/Windows-Live-Writer-Just_AC8F-wlEmoticon-sarcasticsmile_2.png" /&gt;) class.     &lt;br /&gt;&lt;/div&gt;  &lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IVisitor&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;void&lt;/span&gt; VisitDefault(IVisitorTarget source);&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;br /&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;Then the &lt;strong&gt;IVisitorTarget &lt;/strong&gt;interface (implied above) that has to be implemented by the class to be “consumed/visited” by the &lt;strong&gt;Visitor.&lt;/strong&gt; 

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IVisitorTarget&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;void&lt;/span&gt; Accept(IVisitor visitor);&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;

  &lt;br /&gt;Ok, I know, nothing much up to now. But as I say “The longest journey starts with the first step”…(yes I am an old Chinese philosopher) 

  &lt;br /&gt;

  &lt;br /&gt;To have your visitor pattern in place you need an extension method to do the trick: 

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ConcreteVisit(&lt;span class="kwrd"&gt;this&lt;/span&gt; IVisitorTarget target, IVisitor visitor) {&lt;br /&gt;  Type[] types = &lt;span class="kwrd"&gt;new&lt;/span&gt; Type[] { target.GetType() };&lt;br /&gt;  MethodInfo mi = visitor.GetType().GetMethod(&lt;span class="str"&gt;"Visit"&lt;/span&gt;, types);&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (mi == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  mi.Invoke(visitor, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { target });&lt;br /&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;br /&gt;Now that these pieces are in place let’s say we have a class called DisplayNameBuilder that implements the &lt;strong&gt;IVisitor&lt;/strong&gt; interface. Also, let’s say we have a &lt;strong&gt;Customer &lt;/strong&gt;entity in our datasource and we want it to implement the &lt;strong&gt;IVisitorTarget &lt;/strong&gt;interface. All we have to do is open &lt;strong&gt;Customer&lt;/strong&gt; entity in the designer, click Write Code and change the class declaration to: 

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Model : IVisitorTarget&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;make sure you are &lt;strong&gt;using&lt;/strong&gt; the namespace of the class where the above extension method is implemented and implement the &lt;strong&gt;IVisitorTarget&lt;/strong&gt; interface like this: 

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; IVisitorTarget Members&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Accept(IVisitor visitor) {&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;this&lt;/span&gt;.ConcreteVisit(visitor))&lt;br /&gt;    visitor.VisitDefault(&lt;span class="kwrd"&gt;this&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;Also this is a sample implementation of the DisplayNameBuilder class: 

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DisplayNameBuilder : IVisitor&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name{&lt;br /&gt;    get;&lt;br /&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; set;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; VisitDefault(IVisitorTarget visitorTarget){&lt;br /&gt;    Name = visitorTarget.ToString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Visit(Customer visitorTarget){&lt;br /&gt;    Name = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0}{1}{2}"&lt;/span&gt;, visitorTarget.FirstName, &lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(visitorTarget.FirstName) ? &lt;span class="str"&gt;""&lt;/span&gt;, &lt;span class="str"&gt;" "&lt;/span&gt;, visitorTarget.LastName);&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;In the above code please note these: 

  &lt;br /&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;
  &lt;ol&gt;
    &lt;br /&gt;

    &lt;li&gt;The code was written in Live Writer as it’s demo code, so maybe it does not compile as is.&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-embarrassedsmile" alt="Embarrassed smile" src="/Portals/0/Blog/Files/3/152/Windows-Live-Writer-Just_AC8F-wlEmoticon-embarrassedsmile_2.png" /&gt; 

      &lt;br /&gt;&lt;/li&gt;

    &lt;li&gt;The customer is implied to have a nullable &lt;strong&gt;FirstName&lt;/strong&gt; property and a not nullable &lt;strong&gt;LastName &lt;/strong&gt;(which I believe it’s a fair assumption and I agree with me). 

      &lt;br /&gt;&lt;/li&gt;

    &lt;li&gt;The implementation, as obvious, is domain aware as it knows what &lt;strong&gt;Customer &lt;/strong&gt;is. This implies that the ideal place for this class to live is in the &lt;strong&gt;Common &lt;/strong&gt;project. &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;br /&gt;Now lets say you create a calculated string field in Customer entity called hmmmmm… &lt;strong&gt;DisplayName&lt;/strong&gt; (surprised? It’s a gift I have regarding giving original names&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smilewithtongueout" alt="Smile with tongue out" src="/Portals/0/Blog/Files/3/152/Windows-Live-Writer-Just_AC8F-wlEmoticon-smilewithtongueout_2.png" /&gt;). This would be the code that would implement the calculation of &lt;strong&gt;DisplayName&lt;/strong&gt; property: 

&lt;br /&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DisplayName_Compute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; result) {&lt;br /&gt;  DisplayNameBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; DisplayNameBuilder();&lt;br /&gt;  &lt;span class="kwrd"&gt;this&lt;/span&gt;.Accept(builder);&lt;br /&gt;  result = builder.Name;&lt;br /&gt;}&lt;/pre&gt;

&lt;br /&gt;I HAVE to stress one more time that the code is for demonstration purposes only. It’s not just you, it IS too much fuss for nothing. 

&lt;br /&gt;

&lt;br /&gt;Ok, now it should be easier to understand the problem of using the visitor pattern with pre-defined classes. You cannot add the &lt;strong&gt;IVisitorTarget &lt;/strong&gt;behavior to most of the classes, automatically generated by LS. 

&lt;br /&gt;

&lt;br /&gt;So this is the solution to the problem. 

&lt;br /&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; IVisitorWrapper&lt;TObjectType&gt; : IVisitorTarget&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; TObjectType Content {&lt;br /&gt;    get;&lt;br /&gt;    set;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="preproc"&gt;#region&lt;/span&gt; IVisitorTarget Members&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Accept(IVisitor visitor) {&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!this.ConcreteVisit(&lt;span class="kwrd"&gt;this&lt;/span&gt;, visitor))&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!this.VisitWrapper(&lt;span class="kwrd"&gt;this&lt;/span&gt;, visitor))&lt;br /&gt;        visitor.VisitDefault(&lt;span class="kwrd"&gt;this&lt;/span&gt;);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;}&lt;/pre&gt;

&lt;br /&gt;

&lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

&lt;br /&gt;

&lt;br /&gt;This is a wrapper class (one could say it is an &lt;strong&gt;IVisitorTarget&lt;/strong&gt; decorator). If you are still with me and you keep on reading the code you have already noticed that &lt;strong&gt;VisitWrapper&lt;/strong&gt; extension method is not yet defined, so this is it: 

&lt;br /&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; VisitWrapper&lt;TObjectType&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IVisitorWrapper&lt;TObjectType&gt; wrapper, IVisitor visitor) {&lt;br /&gt;  Type[] types = &lt;span class="kwrd"&gt;new&lt;/span&gt; Type[] { &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TObjectType) };&lt;br /&gt;  MethodInfo mi = visitor.GetType().GetMethod(&lt;span class="str"&gt;"Visit"&lt;/span&gt;, types);&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (mi == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  mi.Invoke(visitor, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { wrapper.Content });&lt;br /&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;Now you can wrap any type of object and use the &lt;strong&gt;DisplayNameBuilder &lt;/strong&gt;to build it’s display name&lt;strong&gt;. &lt;/strong&gt;Also (as –I hope- you guessed) you have to implement the respective &lt;strong&gt;Visit&lt;/strong&gt; method in &lt;strong&gt;DisplayNameBuilder&lt;/strong&gt; in order not go get the type name back as &lt;strong&gt;Name&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;This is a small sample of how the wrapper can be used:&lt;/p&gt;

&lt;p&gt;
  &lt;pre class="csharpcode"&gt;WhateverObject objectToWrap = &lt;span class="kwrd"&gt;new&lt;/span&gt; WhateverObject();

DisplayNameBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; DisplayNameBuilder();
&lt;span class="kwrd"&gt;new&lt;/span&gt; IVisitorWrapper&lt;WhateverObject&gt; { Content = objectToWrap }.Accept(builder);

&lt;span class="kwrd"&gt;string&lt;/span&gt; displayName = builder.Name;&lt;/pre&gt;
  &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;Well, as Porky says: That’s all Folks &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/152/Windows-Live-Writer-Just_AC8F-wlEmoticon-smile_2.png" /&gt;. I hope that except for exhausting it was also interesting.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/152/Just-Visiting-or-not-so-Simple-Extension-Methods-part-4.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/152/Just-Visiting-or-not-so-Simple-Extension-Methods-part-4.aspx#Comments</comments>
      <slash:comments>10</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/152/Just-Visiting-or-not-so-Simple-Extension-Methods-part-4.aspx</guid>
      <pubDate>Fri, 13 Jul 2012 10:56:44 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=152</trackback:ping>
    </item>
    <item>
      <title>Simple Extension Methods (part 3)</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/151/Simple-Extension-Methods-part-3.aspx</link>
      <description>&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;One very common task when one is implementing the business logic in Common project is writing custom &lt;em&gt;&lt;strong&gt;PropertyName_Changed&lt;/strong&gt; &lt;/em&gt;partial methods.     &lt;br /&gt;This “approach” has an undesired “side-effect” when the property is an entity property (as compared to screen properties). The property changes many times during the lifetime of the object. While loading, while deleting etc., whereas what we want to implement is handle the “actual” property changes caused either by the user or by some other piece of business logic.     &lt;br /&gt;I found myself debugging code that shouldn’t be executing (according to my logic, obviously LS had another opinion) before ending up writing a small extension method to use in all &lt;strong&gt;&lt;em&gt;PropertyName_Changed&lt;/em&gt;&lt;/strong&gt; partial methods. I don’t claim this method will help you avoid ALL unwanted business logic code execution, but covers most of the cases. I would be glad to read any comments improving it in a generic way.     &lt;br /&gt;Here is the code of the extension method:     &lt;br /&gt;    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IgnorePropertyChange(&lt;span class="kwrd"&gt;this&lt;/span&gt; IEntityObject entity) {&lt;br /&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt; entity.Details.EntityState == EntityState.Unchanged ||&lt;br /&gt;         entity.Details.EntityState == EntityState.Discarded ||&lt;br /&gt;         entity.Details.EntityState == EntityState.Deleted;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;And here how all my property changed partial implementations for entity properties look like 

  &lt;br /&gt;

  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ScheduledEndDate_Changed() {&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.IgnorePropertyChange())&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;br /&gt;  .&lt;br /&gt;  .&lt;br /&gt;  .&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;This looks (and is) simple but the concept, alone, of “unwanted” code execution is important and should be taken good care of. If not using this extension method any other way one may like &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="/Portals/0/Blog/Files/3/151/Windows-Live-Writer-Simple-Extension-Methods-part-3_CA0F-wlEmoticon-winkingsmile_2.png" /&gt;.&lt;/div&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/151/Simple-Extension-Methods-part-3.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/151/Simple-Extension-Methods-part-3.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/151/Simple-Extension-Methods-part-3.aspx</guid>
      <pubDate>Fri, 13 Jul 2012 10:56:00 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=151</trackback:ping>
    </item>
    <item>
      <title>Simple Extension Methods (part 2)</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/150/Simple-Extension-Methods-part-2.aspx</link>
      <description>&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;In the previous post I presented an extension method used mostly for overriding the edit and delete commands of a collection. One may ask “why do I want to do this?”. Apart from any other requirements/business logic dependent reason one might want to implement, for me there is one simple yet important reason: I don’t like at all (to be kind) the default add/edit modal windows when adding or editing an entry. It’s not a coincidence that the &lt;a href="http://code.msdn.microsoft.com/Managing-Custom-AddEdit-5772ab80" target="_blank"&gt;FIRST&lt;/a&gt; sample I wrote for LightSwitch and posted in the Samples of msdn.com/lightswitch was a set of extension methods and contracts to easily replace standard modal windows with custom ones.     &lt;br /&gt;Most of the times when I have an editable grid screen, selecting Add or Edit I DON’T want the modal window to pop-up, I just want to edit in the grid. Or in list and details screen I want to edit the new or existing entry in the detail part of the screen.     &lt;br /&gt;This is the main reason I most of the times override the default Add/Edit command behavior. And for this reason I created and use the next two extension methods:     &lt;br /&gt;    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddFocus&lt;T&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; VisualCollection&lt;T&gt; collection, &lt;span class="kwrd"&gt;string&lt;/span&gt; focusControl, &lt;span class="kwrd"&gt;bool&lt;/span&gt; inCollection)&lt;br /&gt;  &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;, IEntityObject {&lt;br /&gt;  collection.AddNew();&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (focusControl != &lt;span class="kwrd"&gt;null&lt;/span&gt;) {&lt;br /&gt;    &lt;span class="kwrd"&gt;try&lt;/span&gt; {&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (inCollection)&lt;br /&gt;        collection.Screen.FindControlInCollection(focusControl, collection.SelectedItem).Focus();&lt;br /&gt;      &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;        collection.Screen.FindControl(focusControl).Focus();&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;catch&lt;/span&gt; {&lt;br /&gt;      collection.EditSelected();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; EditFocus&lt;T&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; VisualCollection&lt;T&gt; collection, &lt;span class="kwrd"&gt;string&lt;/span&gt; focusControl, &lt;span class="kwrd"&gt;bool&lt;/span&gt; inCollection)&lt;br /&gt;  &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;, IEntityObject {&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (focusControl != &lt;span class="kwrd"&gt;null&lt;/span&gt;) {&lt;br /&gt;    &lt;span class="kwrd"&gt;try&lt;/span&gt; {&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (inCollection)&lt;br /&gt;        collection.Screen.FindControlInCollection(focusControl, collection.SelectedItem).Focus();&lt;br /&gt;      &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;        collection.Screen.FindControl(focusControl).Focus();&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;catch&lt;/span&gt; {&lt;br /&gt;      collection.EditSelected();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;So what you have to do in your MyCollectionAddAndEditNew_Execute partial method is write something like: 

  &lt;br /&gt;

  &lt;pre class="csharpcode"&gt;MyCollection.AddFocus(&lt;span class="str"&gt;"TheNameOfTheControlYouWantToFocus", true&lt;/span&gt;);&lt;/pre&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;or for MyCollectionEdit_Execute partial method: 

  &lt;br /&gt;

  &lt;pre class="csharpcode"&gt;MyCollection.EditFocus(&lt;span class="str"&gt;"TheNameOfTheControlYouWantToFocus", true&lt;/span&gt;);&lt;/pre&gt;

  &lt;br /&gt;if you have a list detail screen the same code applies but with inCollection = false. 

  &lt;br /&gt;

  &lt;br /&gt;One could implement one method for collections and one for details. Also notice &lt;strong&gt;where&lt;/strong&gt; constraints applied to &lt;strong&gt;T&lt;/strong&gt; generic parameter. The &lt;strong&gt;class &lt;/strong&gt;constraint is required for declaring &lt;strong&gt;VisualCollection&lt;T&gt;&lt;/strong&gt;. The &lt;strong&gt;IEntityObject &lt;/strong&gt;constraint is required so that we avoid the arbitrary casting of &lt;strong&gt;collection.SelectedItem &lt;/strong&gt;to &lt;strong&gt;IEntityObject&lt;/strong&gt; so as to be passed to &lt;strong&gt;FindControlInCollection&lt;/strong&gt; as second parameter. 

  &lt;br /&gt;

  &lt;br /&gt;Notice that in the extension methods I don’t check if the control name exists. I just use try catch. On error (if the control name is not valid) I choose to fall-back to the default behavior. You can change this without any intellectual rights being violated &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/150/Windows-Live-Writer-Simple-Extension-Methods-part-2_ACFA-wlEmoticon-smile_2.png" /&gt;.&lt;/div&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/150/Simple-Extension-Methods-part-2.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/150/Simple-Extension-Methods-part-2.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/150/Simple-Extension-Methods-part-2.aspx</guid>
      <pubDate>Fri, 13 Jul 2012 10:55:32 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=150</trackback:ping>
    </item>
    <item>
      <title>Simple Extension Methods (part 1)</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/149/Simple-Extension-Methods-part-1.aspx</link>
      <description>&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;As soon as I started writing LightSwitch applications I noticed that many times I was repeating the same code over and over for trivial tasks. So after all this time I have collected a number of extension methods that I widely use in my apps.    &lt;br /&gt;For me reusing code is a &lt;strong&gt;must&lt;/strong&gt; and although the implementation of LS (IMHO) does not provide for this out of the box the underlying framework is ideal for writing extension classes and methods that are a major step towards code reusability. If you have downloaded any of my samples from msdn or have seen my &lt;a href="http://kostaschristodoulou.blogspot.gr/2012/01/application-logo.html" target="_blank"&gt;Application Logo&lt;/a&gt; post, you already suspect I am an “extension method fanatic”.     &lt;br /&gt;So I will present a small series (I don’t know how small) of posts with extension methods from my Base.LightSwitch.Client library.     &lt;br /&gt;The first method is one of the first (if not the first one) extension methods I wrote. As soon as you want to override the code for default commands like Edit and Delete for a collection (let’s name it MyCollection) you have to write something like that:     &lt;br /&gt;    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt;  &lt;span class="kwrd"&gt;void&lt;/span&gt; MyCollectionDelete_CanExecute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; result){&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.MyCollection &lt;span class="kwrd"&gt;is&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt; || &lt;span class="kwrd"&gt;this&lt;/span&gt;.MyCollection.SelectedItem == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;    result = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;  &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;    result = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;span style="font-family: arial"&gt;This is the minimum code (it can be written more elegantly I know but this is the concept) you need to write. I don’t take into account the permissions issue.&lt;/span&gt; 

  &lt;br /&gt;

  &lt;br /&gt;A similar chunk of code has to be written for Edit. 

  &lt;br /&gt;

  &lt;br /&gt;Isn’t the code listed below easier to read: 

  &lt;br /&gt;

  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt;  &lt;span class="kwrd"&gt;void&lt;/span&gt; MyCollectionDelete_CanExecute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; result){&lt;br /&gt;  result = &lt;span class="kwrd"&gt;this&lt;/span&gt;.HasSelection(&lt;span class="str"&gt;"MyCollection"&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial"&gt;It’s not only easier to read but is less error prone than the original. Plus you can inject any security logic in this &lt;strong&gt;HasSelection&lt;/strong&gt; method.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial"&gt;And this is the code:&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; HasSelection(&lt;span class="kwrd"&gt;this&lt;/span&gt; IScreenObject screen, &lt;span class="kwrd"&gt;string&lt;/span&gt; collectionName) {&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (!screen.Details.Properties.Contains(collectionName))&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;  IVisualCollection collection =&lt;br /&gt;    screen.Details.Properties[collectionName].Value &lt;span class="kwrd"&gt;as&lt;/span&gt; IVisualCollection;&lt;br /&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt; collection != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;&amp;&lt;br /&gt;         collection.SelectedItem != &lt;span class="kwrd"&gt;null &lt;span style="color: black"&gt;&amp;&amp;&lt;br /&gt;&lt;br /&gt;         (collection.SelectedItem as IEntityObject).Details.EntityState != EntityState.Deleted&lt;/span&gt;&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial"&gt;For the ones that dislike using string property names I can suggest this version :&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; HasSelection&lt;T&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; VisualCollection&lt;T&gt; collection) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;, IEntityObject {&lt;br /&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt; collection != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;&amp;&lt;br /&gt;         collection.SelectedItem != nul &amp;&amp;&lt;br /&gt;         collection.SelectedItem.Details.EntityState != EntityState.Deleted;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial"&gt;This version is more concrete is generic and also does not have to do the (out of thin air) conversion of SelectedItem to IEntityObject. If you use this version though you have to change your partial method as you cannot extend null:&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MyCollectionDelete_CanExecute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; result){&lt;br /&gt;  result = MyCollection!= null &amp;&amp; MyCollection.HasSelection();&lt;br /&gt;}&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span style="font-family: arial"&gt;The choice is yours…&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/149/Windows-Live-Writer-1f24f4e94b47_7FF0-wlEmoticon-smile_2.png" /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/149/Simple-Extension-Methods-part-1.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/149/Simple-Extension-Methods-part-1.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/149/Simple-Extension-Methods-part-1.aspx</guid>
      <pubDate>Fri, 13 Jul 2012 10:55:15 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=149</trackback:ping>
    </item>
    <item>
      <title>Application Logo (tailored on customer demand)</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/147/Application-Logo-tailored-on-customer-demand.aspx</link>
      <description>&lt;div style="text-align: left" dir="ltr" trbidi="on"&gt;This is the most recent comment in the &lt;a href="http://kostaschristodoulou.blogspot.gr/2012/02/application-logo-sample.html" target="_blank"&gt;Application Logo Sample&lt;/a&gt; post:     &lt;br /&gt;&lt;em&gt;“Hi Kostas,      &lt;br /&gt;I wanted to find out if there is a way of opening an active screen as soon as I click on the logo. I have tried but my attempt was in vain. If it is possible, could you please help me out?       &lt;br /&gt;Thanks,       &lt;br /&gt;Darryn”&lt;/em&gt;     &lt;br /&gt;My first reaction was to ask for details (typical way of buying time &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="/Portals/0/Blog/Files/3/147/Windows-Live-Writer-Application-Logo-Revised_E955-wlEmoticon-smile_2.png" /&gt;). But then I though I could do the changes required and post a new article. So simply put, this is the answer I propose to Darryn:     &lt;br /&gt;    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddLogo(&lt;span class="kwrd"&gt;this&lt;/span&gt; Microsoft.LightSwitch.Client.IClientApplication application, System.Windows.HorizontalAlignment alignment, &lt;b&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; screenName&lt;/b&gt;) {&lt;br /&gt;  Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =&gt; { LogoPlacement.AddLogo(&lt;b&gt;application&lt;/b&gt;, System.Windows.Application.Current.RootVisual, alignment, &lt;strong&gt;screenName&lt;/strong&gt;); });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; LogoPlacement&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddLogo(&lt;strong&gt;Microsoft.LightSwitch.Client.IClientApplication application&lt;/strong&gt;, UIElement element, System.Windows.HorizontalAlignment alignment, &lt;strong&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; screenName&lt;/strong&gt;) {&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (rcb != &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &lt; System.Windows.Media.VisualTreeHelper.GetChildrenCount(element); i++) {&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (rcb != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;br /&gt;      UIElement child = (UIElement)System.Windows.Media.VisualTreeHelper.GetChild(element, i);&lt;br /&gt;      AddLogo(application, child, alignment, screenName);&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (element &lt;span class="kwrd"&gt;is&lt;/span&gt; Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard.RibbonCommandBar) {&lt;br /&gt;      rcb = element &lt;span class="kwrd"&gt;as&lt;/span&gt; Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard.RibbonCommandBar;&lt;br /&gt;      Image myImage = &lt;span class="kwrd"&gt;new&lt;/span&gt; Image() {&lt;br /&gt;        Stretch = System.Windows.Media.Stretch.Uniform,&lt;br /&gt;        Margin = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(2, 8, 14, 8),&lt;br /&gt;        HorizontalAlignment = alignment,&lt;br /&gt;        Cursor = System.Windows.Input.Cursors.Hand&lt;br /&gt;      };&lt;br /&gt;      myImage.SetValue(ComponentViewModelService.ViewModelNameProperty, &lt;span class="str"&gt;"Default.LogoViewModel"&lt;/span&gt;);&lt;br /&gt;      myImage.SetBinding(Image.SourceProperty, &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Windows.Data.Binding { Path = &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyPath(&lt;span class="str"&gt;"Logo"&lt;/span&gt;) });&lt;br /&gt;      &lt;strong&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(screenName))&lt;/strong&gt;&lt;br /&gt;        myImage.MouseLeftButtonUp += (s, e) =&gt; { &lt;strong&gt;application.Details.Dispatcher.BeginInvoke(() =&gt; application.Details.Methods[&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Show{0}"&lt;/span&gt;, screenName)].CreateInvocation().Execute()); };&lt;/strong&gt;&lt;br /&gt;      myImage.SizeChanged += (s, e) =&gt; {&lt;br /&gt;        &lt;span class="kwrd"&gt;double&lt;/span&gt; left = (s &lt;span class="kwrd"&gt;as&lt;/span&gt; Image).HorizontalAlignment == HorizontalAlignment.Left ? e.NewSize.Width + 10.0 : 0.0;&lt;br /&gt;        &lt;span class="kwrd"&gt;double&lt;/span&gt; right = (s &lt;span class="kwrd"&gt;as&lt;/span&gt; Image).HorizontalAlignment == HorizontalAlignment.Right ? e.NewSize.Width + 10.0 : 0.0;&lt;br /&gt;        rcb.Padding = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(left, 0, right, 0);&lt;br /&gt;      };&lt;br /&gt;      ((Grid)rcb.Parent).Children.Add(myImage);&lt;br /&gt;    }&lt;br /&gt;  }&lt;/pre&gt;

  &lt;br /&gt;

  &lt;br /&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;

  &lt;br /&gt;

  &lt;br /&gt;With bold I have marked the additions/changes I had to make to accommodate Darryn’s request. 

  &lt;br /&gt;I hope Darryn is happy &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smilewithtongueout" alt="Smile with tongue out" src="/Portals/0/Blog/Files/3/147/Windows-Live-Writer-Application-Logo-Revised_E955-wlEmoticon-smilewithtongueout_2.png" /&gt;.&lt;/div&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/147/Application-Logo-tailored-on-customer-demand.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/147/Application-Logo-tailored-on-customer-demand.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/147/Application-Logo-tailored-on-customer-demand.aspx</guid>
      <pubDate>Thu, 12 Jul 2012 07:31:35 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=147</trackback:ping>
    </item>
    <item>
      <title>CLASS Extensions Version 2 Released</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/123/CLASS-Extensions-Version-2-Released.aspx</link>
      <description>&lt;p&gt;&lt;a href="http://kostaschristodoulou.blogspot.com/p/class-extnesions-version-2.html" target="_blank"&gt;CLASS Extensions version 2 is now available&lt;/a&gt;. All the features demonstrated in the &lt;a href="http://kostaschristodoulou.blogspot.com/2012/03/class-extensions-version-2-demo.html" target="_blank"&gt;demo videos&lt;/a&gt; are included plus the AttachmentsListEx collection control that is demostrated in the sample application but was not mentioned in the previous post.&lt;/p&gt;  &lt;h3&gt;Features&lt;/h3&gt;  &lt;li&gt;&lt;strong&gt;Color Business type and Controls&lt;/strong&gt;. This business type is used to represent color values. The underlying CLR type is &lt;strong&gt;integer&lt;/strong&gt;. After a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/25722a43-2a9d-4e86-86e5-7f39cc803018/#d1a81e31-07dd-4fab-bdbf-f300bf023a5a" target="_blank"&gt;request&lt;/a&gt; the change from the previous free version is that by default the pop-up window color picker control is used both for details and collections. Boolean property called “Drop Down” was added in the Appearance category which is false by default. When checked the drop-down/expander color picker control is used instead. This property is &lt;strong&gt;ignored &lt;/strong&gt;in collections (grids/lists etc.) and pop-up is used.&lt;strong&gt; &lt;/strong&gt;The color-picker control (as mentioned in the first version also) is contained in &lt;a href="http://silverlightcontrib.codeplex.com/" target="_blank"&gt;SilverlightContrib&lt;/a&gt; Codeplex project under Ms-PL.  &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_2.png"&gt;&lt;strong&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb.png" width="150" height="244" /&gt;&lt;/strong&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Boolean Checkbox &amp; Boolean Viewer controls.&lt;/strong&gt; These controls handle bool and bool? (Nullable&lt;bool&gt;) values. No changes made from the previous – free – version.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-checked_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="checked" border="0" alt="checked" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-checked_thumb.png" width="23" height="23" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-checked_dimmed_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="checked_dimmed" border="0" alt="checked_dimmed" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-checked_dimmed_thumb.png" width="23" height="23" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-unchecked_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="unchecked" border="0" alt="unchecked" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-unchecked_thumb.png" width="23" height="23" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-uncheckeddimmed_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="uncheckeddimmed" border="0" alt="uncheckeddimmed" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-uncheckeddimmed_thumb.png" width="23" height="23" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-undefinedcheck_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="undefinedcheck" border="0" alt="undefinedcheck" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-undefinedcheck_thumb.png" width="23" height="23" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-undefinedcheck_dimmed_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="undefinedcheck_dimmed" border="0" alt="undefinedcheck_dimmed" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-undefinedcheck_dimmed_thumb.png" width="23" height="23" /&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Rating Business type and Controls.&lt;/strong&gt; This business type is used to represent rating values. The underlying CLR type is &lt;strong&gt;integer&lt;/strong&gt;. The control is using the Mark Heath’s &lt;a href="http://starratingcontrol.codeplex.com/" target="_blank"&gt;Silverlight Star Rating Control&lt;/a&gt; from CodePlex under Ms-PL.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_10.png" width="121" height="28" /&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Percentage Business type and Controls. &lt;/strong&gt;This business type is used to represent percentages. The underlying CLR type is &lt;strong&gt;decimal.&lt;/strong&gt; In read-only mode a progress bar is displayed which is green for percentages &lt;= 100% and red otherwise. It’s ideal for representing progress.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_1.png" width="66" height="28" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_2.png" width="68" height="28" /&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;ImageURI Business type and Controls. &lt;/strong&gt;This business type is used to display an image from a URI location. The underlying CLR type is &lt;strong&gt;string&lt;/strong&gt;. You can define a thumbnail view and size and also choose if the URI should be visible (editable if not read-only). &lt;strong&gt;Stretch Image&lt;/strong&gt; property applies &lt;strong&gt;Uniform&lt;/strong&gt; stretch to the image.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_3.png" width="360" height="292" /&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;AudioFile Business type and Controls.&lt;/strong&gt;This business type is used to store and reproduce audio files from a URI location. The underlying CLR type is &lt;strong&gt;string&lt;/strong&gt;. You can choose if the URI should be visible (editable if not read-only). Play, Pause, Stop, Volume Control are available. Progress is also displayed.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_4.png" width="211" height="28" /&gt;&lt;/a&gt;  &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;VideoFile Business type and Controls. &lt;/strong&gt;This business type is used to store and reproduce video files from a URI location. The underlying CLR type is &lt;strong&gt;string.&lt;/strong&gt; You can choose if the URI should be visible (editable if not read-only). Play, Pause, Stop, Volume Control are available. Progress is also displayed.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_5.png" width="359" height="278" /&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;DrawingFile type and Control.&lt;/strong&gt; This business type is used to store drawings. The underlying CLR type is &lt;strong&gt;string&lt;/strong&gt;.&lt;strong&gt; &lt;/strong&gt;The background of the drawing is defined as an image URI (not binary). Using the control you can draw lines, polygons and texts on a layer over the image store and edit afterwards to delete drawings, move edit or delete texts, change fonts and colors e.t.c. The control can also operate in local mode, where all drawings are saved in application’s Isolated Storage. Every time a drawing is saved a png image snapshot of the drawing is also generated and can be easily (with 2 lines of code) saved in traditional Image (byte[]) fields.     &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_6.png" width="354" height="296" /&gt;&lt;/a&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_7.png" width="355" height="302" /&gt;&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;AttachmentsListEx Collection Control. &lt;/strong&gt;This is a special use collection control used to represent collections of entities implementing &lt;strong&gt;CLASSExtensions.Contracts.IAttachment.      &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_8.png" width="102" height="30" /&gt;&lt;/a&gt;&lt;/strong&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;FileServer Datasource Extension.&lt;/strong&gt; A very important RIA Service datasource provided to smoothly integrate all the URI-based features. This Datasource exports two entity types: &lt;strong&gt;ServerFile&lt;/strong&gt; and &lt;strong&gt;ServerFileType&lt;/strong&gt;. Also provides methods to retrieve &lt;strong&gt;ServerFile&lt;/strong&gt; entities representing the content files (Image, Audio, Video, Document, In the current version these are the &lt;strong&gt;ServerFileTypes&lt;/strong&gt; supported) stored at your application server. Also you can delete &lt;strong&gt;ServerFile&lt;/strong&gt; entities. Upload (insert/update) is not implemented in this version as depending on Whether your application is running out of browser or not it has to be done a different way. Maybe in an update. The idea for this datasource was based on &lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/35/Saving-Files-To-File-System-With-LightSwitch-Uploading-Files.aspx" target="_blank"&gt;this&lt;/a&gt; article of Michael Washington. &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;A good numbered (30+) collection of ValueConverters and Extension Classes.&lt;/strong&gt; You can reuse in your applications either to create your own custom controls and extensions or application code in general.     &lt;p&gt; &lt;/p&gt;    &lt;h3&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/h3&gt;    &lt;h3&gt;Pricing&lt;/h3&gt;    &lt;p&gt;The price is 50$ for the package without the code. Depending on demand a code inclusive version and pricing may become available. The payment is done through PayPal and if invoice is required will be sent by post.&lt;/p&gt;    &lt;h3&gt;&lt;strong&gt;Remarks&lt;/strong&gt;&lt;/h3&gt;    &lt;ul&gt;     &lt;li&gt;Regarding &lt;strong&gt;Rating business type &lt;/strong&gt;the Maximum and Default rating properties have to be set on the control. Although I found I way to add attributes to the business type, I couldn’t find a way to retrieve in the control so that these parameters could be set once on the entity’s property. &lt;/li&gt;      &lt;li&gt;The reason &lt;strong&gt;DrawingFile&lt;/strong&gt; is using URI as image background and not a binary image was a result of my intention to create a lightweight drawing type which is also portable. As long as the image URI is public the drawings can be ported to any other application using the extension copying just a few KBs. &lt;/li&gt;      &lt;li&gt;For the &lt;strong&gt;FileServer Datasource &lt;/strong&gt;to work you must create a folder hierarchy in your web application’s folder. You have to create a &lt;strong&gt;Content&lt;/strong&gt; (see also ContentDirectory appSetting below) sub-folder in the root folder of your application and a hierarchy like shown below. If the folders are not there, an attempt will be made by code to be created, but to avoid extra permissions issues you can create in advance. Also if you want to be able to delete files you have to take care of file permissions so that the account can delete files.  &lt;br /&gt;&lt;a href="http://lightswitchhelpwebsite.com/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/123/Windows-Live-Writer-CLASS-E_91F7-image_thumb_9.png" width="92" height="89" /&gt;&lt;/a&gt;         &lt;br /&gt;Also, as you can see in the sample application you will receive along with the extensions, in ServerGenerated\web.config there are 2 appSettings entries:         &lt;br /&gt;        &lt;br /&gt;&lt;add key="VirtualDirectory" value="" /&gt;         &lt;br /&gt;&lt;add key="ContentDirectory" value="Content" /&gt;         &lt;br /&gt;        &lt;br /&gt;The first one &lt;strong&gt;VirtualDirectory&lt;/strong&gt; is compulsory and if your application is not running at the root of the publishing site the value should be the name of the virtual directory under which your application is running. In the sample the value is null.         &lt;br /&gt;The second one &lt;strong&gt;ContentDirectory&lt;/strong&gt; is optional and if omitted then &lt;strong&gt;Content&lt;/strong&gt; is assumed as the folder to look for files. &lt;/li&gt;      &lt;li&gt;For all URI based types: If you are using the &lt;strong&gt;FileServer Datasource&lt;/strong&gt; while debugging you will have issues regarding the validity of the URIs. As between builds and runs the host’s port can change, a URI provided from the &lt;strong&gt;FileServer Datasource&lt;/strong&gt; (containing the current port) during one debug session, may be invalid in a next session if the port changes. Of course after deployment this will never be an issue unless you somehow change your application’s URL. &lt;/li&gt;   &lt;/ul&gt;     &lt;/li&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/123/CLASS-Extensions-Version-2-Released.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/123/CLASS-Extensions-Version-2-Released.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/123/CLASS-Extensions-Version-2-Released.aspx</guid>
      <pubDate>Fri, 23 Mar 2012 11:05:03 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=123</trackback:ping>
    </item>
    <item>
      <title>CLASS Extensions Version 2 Demo</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/121/CLASS-Extensions-Version-2-Demo.aspx</link>
      <description>&lt;p&gt;After a long time of preparation, my company &lt;a href="http://www.computerlife.gr" target="_blank"&gt;Computer Life&lt;/a&gt; and me we are ready to publish the next –commercial- version of CLASS Extensions.&lt;/p&gt;
&lt;p&gt;In &lt;a href="https://skydrive.live.com/?cid=6C344D9AD6A0DEC2&amp;id=6C344D9AD6A0DEC2%21200&amp;sc=documents" target="_blank"&gt;this&lt;/a&gt; SkyDrive location you can find 2 videos briefly presenting capabilities of this new version. In less than a week a page will be started, where you would be able to buy the package you prefer. There will be 2 packages: no source code and with code and code documentation. Pricing will be announced along with the official release.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://skydrive.live.com/?cid=6C344D9AD6A0DEC2&amp;id=6C344D9AD6A0DEC2%21200&amp;sc=documents" target="_blank"&gt;CLASS Extensions Demo Part I.swf&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://skydrive.live.com/?cid=6C344D9AD6A0DEC2&amp;id=6C344D9AD6A0DEC2%21200&amp;sc=documents" target="_blank"&gt;&lt;img style="background-image: none;  padding-left: 0px; padding-right: 0px; display: inline;    padding-top: 0px;    border-width: 0px;border-style: solid;" title="Part1" alt="Part1" src="/Portals/0/Blog/Files/3/121/Windows-Live-Writer-CLASS_BFA3-Part1_1.png" width="244" height="133" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://skydrive.live.com/?cid=6C344D9AD6A0DEC2&amp;id=6C344D9AD6A0DEC2%21200&amp;sc=documents" target="_blank"&gt;CLASS Extensions Demo Part II.swf&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://skydrive.live.com/?cid=6C344D9AD6A0DEC2&amp;id=6C344D9AD6A0DEC2%21200&amp;sc=documents"&gt;&lt;img style="background-image: none;  padding-left: 0px; padding-right: 0px; display: inline;    padding-top: 0px;    border-width: 0px;border-style: solid;" title="Part2" alt="Part2" src="/Portals/0/Blog/Files/3/121/Windows-Live-Writer-CLASS_BFA3-Part2_1.png" width="244" height="153" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In these videos you will find a brief demonstration of the following controls and/or business types:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Color Business Type and Control&lt;/strong&gt;. This was available also in the first free version. It has been improved to automatically detect grid or detail and read-only or not. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;BooleanCheckbox and BooleanViewer controls.&lt;/strong&gt; These were also available in the first version. No change to this one. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Rating Business Type and Control.&lt;/strong&gt; A new business type to support ratings. You can set maximum rating, star size, show/hide starts and/or labels, allow/disallow half stars. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Image Uri Business Type and Control. &lt;/strong&gt;A new business type to support displaying images from a URI location instead of binary data. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Audio Uri Business Type and Control. &lt;/strong&gt;A new business type to support playing audio files from a URI location. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Video Uri Business Type and Control. &lt;/strong&gt;A new business type to support playing video files from a URI location. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Drawing Business Type and Control.&lt;/strong&gt;  A new business type that allows the user to create drawings using an image URI (not binary) as background. The drawing can be saved either as a property of an entity (the underlying type is string) or in the IsolatedStorage of the application. Also, every time the drawing is saved a PNG snapshot of the drawing is available and can be used any way you want, with 2 (two) lines of additional code. The drawings, both local or data service provided, can be retrieved any time and modified and saved back again. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;FileServer Datasource Extension.&lt;/strong&gt; A very important RIA Service datasource provided to smoothly integrate all the URI-based features. This Datasources exports two EntityTypes: ServerFile and ServerFileType. Also provides methods to retrieve ServerFile entities representing the content files (Image, Audio, Video, Document, In the current version these are the ServerFileTypes supported) stored at your application server. Also you can delete ServerFile entities. Upload (insert/update) is not implemented in this version as depending on Whether your application is running out of browser or not it has to be done a different way. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Last but not least. There is a list of people whose code and ideas helped me a lot in the implementation of this version. Upon official release they will be properly mentioned as community is priceless.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/121/CLASS-Extensions-Version-2-Demo.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/121/CLASS-Extensions-Version-2-Demo.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/121/CLASS-Extensions-Version-2-Demo.aspx</guid>
      <pubDate>Fri, 16 Mar 2012 22:00:00 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=121</trackback:ping>
    </item>
    <item>
      <title>Re-Views</title>
      <link>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/102/Re-Views.aspx</link>
      <description>&lt;p&gt;In previous &lt;a href="http://kostaschristodoulou.blogspot.com/2011/10/sort-this-you-light-of-switch.html" target="_blank"&gt;posts&lt;/a&gt; I made reference to views (DB or RIA) as an alternative (amongst other well-known potentials of views) to search and sort against fields that would normally be relations (lookups or however you want to call them).&lt;/p&gt;
&lt;p&gt;From the very beginning I had an issue with SQL Server views imported to LS. LightSwitch had a very strange way to define the primary keys of the views. These “inferred” primary keys are most of the time very complex combined keys. And this is not an issue actually until you decide to add a relationship between this view (which 99% of the times has only one field as actual primary key) and another table. Then you realize this, otherwise benign, complex primary key is an issue (to say the least).&lt;/p&gt;
&lt;p&gt;It was only recently, in this &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/560532c7-fb8b-499f-8422-aef49feed12b/#f2bf1ed1-2923-4172-80e0-796550fcb327" target="_blank"&gt;thread&lt;/a&gt;, after Yann Duran’s suggested reading (always to the rescue and always having something useful to contribute), that I managed to both understand how LS “infers” the Primary Key for a View and realize how one can “force” a primary key.&lt;/p&gt;
&lt;p&gt;The bottom line is that LS decides that all not-nullable fields will be part of the inferred primary key. Not very inspired but I must admit I cannot think of anything better. So, how one can force the primary key one wants? The way is re-introducing all you not-nullable, non-key fields by cast/convert to the same data-type (or another one if needed). This way the definition of the “table”/”view” imported by LS contains all, originally not nullable fields, as nullable.&lt;/p&gt;
&lt;p&gt;Very short example. Imagine Table Person as&lt;/p&gt;
&lt;p&gt;Id int not null, PK    &lt;br /&gt;
LastName nvarchar(50) not null,     &lt;br /&gt;
FirstName nvarchar(50) null,     &lt;br /&gt;
.     &lt;br /&gt;
.     &lt;br /&gt;
.&lt;/p&gt;
&lt;p&gt;Your view’s SQL would be&lt;/p&gt;
&lt;p&gt;select Id, CONVERT(nvarchar(50), LastName) as LastName, FirstName    &lt;br /&gt;
from Person&lt;/p&gt;
&lt;p&gt;Simple, dummy example just to display what I mean.&lt;/p&gt;
&lt;p&gt;I feel I am re-inventing the wheel as this information was already out there, but in Greece we say “Επανάληψη μήτηρ μαθήσεως” or “Repetition is the mother of Learning” or something like that. Looks like we never learned much from this anyways… &lt;br /&gt;
&lt;br /&gt;
P.S. After Yann's suggestion I have to note that actually this inferred primary key mechanism is Entity Framwork's native and not LightSwitch own behaviour. Although I had that in my mind I didn't make it clear here. I apologize for any missunderstanding and I thank Yann once more for the comment. &lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;&lt;a href=http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/102/Re-Views.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/102/Re-Views.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/102/Re-Views.aspx</guid>
      <pubDate>Mon, 06 Feb 2012 22:00:00 GMT</pubDate>
      <trackback:ping>http://lightswitchhelpwebsite.comDesktopModules/BlogTrackback.aspx?id=102</trackback:ping>
      <blog:tag blog:url="http://lightswitchhelpwebsite.com/Blog/tabid/61/TagID/9/Default.aspx">Concepts</blog:tag>
      <blog:tag blog:url="http://lightswitchhelpwebsite.com/Blog/tabid/61/TagID/3/Default.aspx">Intermediate</blog:tag>
    </item>
  </channel>
</rss>