<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Bernhard Elbl&#039;s Blog</title>
	<atom:link href="http://bernhardelbl.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bernhardelbl.wordpress.com</link>
	<description>development</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:32:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bernhardelbl.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Bernhard Elbl&#039;s Blog</title>
		<link>http://bernhardelbl.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bernhardelbl.wordpress.com/osd.xml" title="Bernhard Elbl&#039;s Blog" />
	<atom:link rel='hub' href='http://bernhardelbl.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Solution: Mapped SkyDrive folder is slow in Windows Explorer</title>
		<link>http://bernhardelbl.wordpress.com/2011/10/10/solution-mapped-skydrive-folder-is-slow-in-windows-explorer/</link>
		<comments>http://bernhardelbl.wordpress.com/2011/10/10/solution-mapped-skydrive-folder-is-slow-in-windows-explorer/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 08:27:51 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[SkyDrive]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/?p=114</guid>
		<description><![CDATA[After mapping my SkyDrive in Windows Explorer, it is was unacceptable slow. After turning off the following setting, everything is working well. Solution Open Internet Options in IE, &#8220;Tools&#8221;&#62; &#8220;Internet Options&#8221; Click the &#8220;Connections&#8221; tab, then &#8220;LAN Settings&#8221; Uncheck &#8220;Automatically detect settings&#8221; Found at&#8230; http://www.technibble.com/forums/showthread.php?t=21954<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=114&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After mapping my SkyDrive in Windows Explorer, it is was unacceptable slow. After turning off the following setting, everything is working well.</p>
<p><strong>Solution</strong><br />
Open Internet Options in IE, &#8220;Tools&#8221;&gt; &#8220;Internet Options&#8221;<br />
Click the &#8220;Connections&#8221; tab, then &#8220;LAN Settings&#8221;<br />
Uncheck &#8220;Automatically detect settings&#8221;</p>
<p>Found at&#8230;<br />
<a href="http://www.technibble.com/forums/showthread.php?t=21954" title="http://www.technibble.com/forums/showthread.php?t=21954" target="_blank">http://www.technibble.com/forums/showthread.php?t=21954</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=114&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2011/10/10/solution-mapped-skydrive-folder-is-slow-in-windows-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>
	</item>
		<item>
		<title>HOWTO: Detect design mode in WPF, ASP .NET and Windows Forms applications</title>
		<link>http://bernhardelbl.wordpress.com/2011/06/16/howto-detecting-design-mode-in-wpf-asp-net-and-windows-forms-applications/</link>
		<comments>http://bernhardelbl.wordpress.com/2011/06/16/howto-detecting-design-mode-in-wpf-asp-net-and-windows-forms-applications/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 11:21:35 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/?p=86</guid>
		<description><![CDATA[If you want to detect the design mode in code, I&#8217;m using the following method, that is working fine for WPF, ASP .NET and Windows Forms applications. It&#8217;s easy, stable, bug free and has a very good performance. I always had troubles by using the built-in methods of .NET Framework like the System.ComponentModel.Component.DesignMode property. For [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=86&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you want to detect the design mode in code, I&#8217;m using the following method, that is working fine for WPF, ASP .NET and Windows Forms applications. It&#8217;s easy, stable, bug free and has a very good performance.</p>
<p><pre class="brush: csharp; gutter: false; wrap-lines: false;">
static class Util
{
    /// &lt;summary&gt;
    /// Contains true, if we are in design mode of Visual Studio
    /// &lt;/summary&gt;
    private static bool _designMode;

    /// &lt;summary&gt;
    /// Initializes an instance of Util class
    /// &lt;/summary&gt;
    static Util()
    {
        // design mode is true if host process is: Visual Studio, Visual Studio Express Versions (C#, VB, C++) or SharpDevelop
        var designerHosts = new List&lt;string&gt;() { &quot;devenv&quot;, &quot;vcsexpress&quot;, &quot;vbexpress&quot;, &quot;vcexpress&quot;, &quot;sharpdevelop&quot; };
        var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToLower();
        _designMode = designerHosts.Contains(processName);
    }

    /// &lt;summary&gt;
    /// Gets true, if we are in design mode of Visual Studio etc..
    /// &lt;/summary&gt;
    public static bool DesignMode
    {
        get
        {
            return _designMode;
        }
    }
}
</pre></p>
<p>I always had troubles by using the built-in methods of .NET Framework like the System.ComponentModel.Component.DesignMode property. For ASP.NET and WPF there exist other methods to determine the design mode. For me the above one replaces all others and works like a charm.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=86&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2011/06/16/howto-detecting-design-mode-in-wpf-asp-net-and-windows-forms-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>
	</item>
		<item>
		<title>RibbonGenerator for Visual Studio 2010 Express Editions: Windows Ribbon for WinForms</title>
		<link>http://bernhardelbl.wordpress.com/2010/12/10/ribbongenerator-for-visual-studio-2010-express-editions-windows-ribbon-for-winforms/</link>
		<comments>http://bernhardelbl.wordpress.com/2010/12/10/ribbongenerator-for-visual-studio-2010-express-editions-windows-ribbon-for-winforms/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 14:22:56 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/?p=61</guid>
		<description><![CDATA[Yes, RibbonGenerator is also working with Express Editions of Visual Studio 2010, but in version 2.6 of the Ribbon library you need some extra effort to bring the tool up to work. Requirements: Windows 7 SDK Visual  C++ 2010 Express Visual C# or Basic 2010 Express Note: You must have Visual C++ 2010 Express Edition [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=61&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yes, RibbonGenerator is also working with Express Editions of Visual Studio 2010, but in version 2.6 of the <a href="http://windowsribbon.codeplex.com/">Ribbon library</a> you need some extra effort to bring the tool up to work.</p>
<p><strong>Requirements:</strong></p>
<ul>
<li> Windows 7 SDK</li>
<li><span style="text-decoration:underline;">Visual  C++ 2010 Express</span></li>
<li>Visual C# or Basic 2010 Express</li>
</ul>
<p>Note: You must have Visual C++ 2010 Express Edition installed because it contains the link.exe file that is need to generate .ribbon files.</p>
<p><strong>Manual Registration of Custom Tool</strong></p>
<p>Because the RibbonGenerator setup is not included in compiled format and because the Express Editions does not support setup projects, it is necessary to register the custom tool manually.</p>
<ol>
<li>Start the &#8220;.\RibbonLib_v2.6\RibbonGenerator\RibbonGenerator.sln&#8221; solution and ignore all errors</li>
<li>Compile it</li>
<li>Install the RibbonGenerator.dll into the GAC using gacutil.exe in Visual Studio 2010 Command Prompt (Run as Administrator)<br />
gacutil &#8211; i RibbonGenerator.dll</li>
<li>Register the custom tool in Express Edition of Visual Studio 2010. The simplest way is to modify the existing .reg in the RibbonGenerator source folder. Choose the x64 reg file if you have a 64bit operating system. .\RibbonGenerator\RegisterCustomTool_VS2010.reg<br />
.\RibbonGenerator\RegisterCustomTool_VS2010_x64.reg<br />
Let take a look into the second one</li>
</ol>
<pre>Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\CLSID\{B64582D9-A489-42F4-BA55-BB6039D82916}]
@="RibbonGenerator"
"InprocServer32"="C:\\WINDOWS\\system32\\mscoree.dll"
"Class"="RibbonGenerator.CustomTool"
"Assembly"="RibbonGenerator, Version=1.0.1.0, Culture=neutral, PublicKeyToken=3cf107c5d7e68b1c"
"ThreadingModel"="Both"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Generators\{164B10B9-B200-11D0-8C61-00A0C91E29D5}\RibbonGenerator]
@="Ribbon Generator"
"CLSID"="{B64582D9-A489-42F4-BA55-BB6039D82916}"
"GeneratesDesignTimeSource"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Generators\{E6FDF8B0-F3D1-11D4-8576-0002A516ECE8}\RibbonGenerator]
@="Ribbon Generator"
"CLSID"="{B64582D9-A489-42F4-BA55-BB6039D82916}"
"GeneratesDesignTimeSource"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Generators\{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}\RibbonGenerator]
@="Ribbon Generator"
"CLSID"="{B64582D9-A489-42F4-BA55-BB6039D82916}"
"GeneratesDesignTimeSource"=dword:00000001
</pre>
<p>All we have to do now, is to place the correct keys for Express Editions</p>
<p>For Visual Studio 2010 (64bit Operating System)</p>
<pre>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\<strong>VisualStudio</strong>\10.0</pre>
<p>For Visual C# 2010 Express (64bit Operating System)</p>
<pre>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\<strong>VCSExpress</strong>\10.0</pre>
<p>For Visual Basic 2010 Express (64bit Operating System)</p>
<pre>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\<strong>VBExpress</strong>\10.0</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=61&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2010/12/10/ribbongenerator-for-visual-studio-2010-express-editions-windows-ribbon-for-winforms/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>
	</item>
		<item>
		<title>RibbonGenerator Details: Windows Ribbon for WinForms</title>
		<link>http://bernhardelbl.wordpress.com/2010/12/10/ribbongenerator-details-windows-ribbon-for-winforms/</link>
		<comments>http://bernhardelbl.wordpress.com/2010/12/10/ribbongenerator-details-windows-ribbon-for-winforms/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 13:46:35 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/?p=39</guid>
		<description><![CDATA[Let take a look into the details of RibbonGenerator of Windows Ribbon for WinForms What is RibbonGenerator doing? It generates .ribbon files that contains the definition of the commands and controls and can be used to display a Ribbon control on a Windows Form. What type of application is RibbonGenerator? There two applications available that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=39&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let take a look into the details of RibbonGenerator of <a href="http://windowsribbon.codeplex.com/">Windows Ribbon for WinForms</a></p>
<p><strong>What is RibbonGenerator doing?</strong><br />
It generates .ribbon files that contains the definition of the commands and controls and can be used to display a Ribbon control on a Windows Form<strong>.<br />
</strong></p>
<p><strong>What type of application is RibbonGenerator?</strong><br />
There two applications available that can be used to generate .ribbon files.</p>
<ul>
<li>A custom tool that can be used directly inside Visual Studio and</li>
<li>A console application that can be used from command line</li>
</ul>
<p>Both application are having the same functionality.</p>
<p><strong>How is RibbonGenerator generating .ribbon files?</strong><br />
Because there is no API available, the tool is &#8220;just&#8221; executing a .bat file. It is a custom .bat file. The content is created by the tool. After the first invocation the &#8220;template.bat&#8221; is placed in the following folder:<br />
<code>C:\Users\&lt;username&gt;\AppData\Local\RibbonGenerator</code><br />
You can customize it. When you delete it, it will be recreated after the next invocation of RibbonGenerator.</p>
<p><strong>What does this .bat file doing?<br />
</strong>Let take a look into the template.bat file.</p>
<pre>"C:\Program Files\Microsoft SDKs\Windows\v7.0\bin\UICC.exe" "{XmlFilename}" "{BmlFilename}" /res:"{RcFilename}"
"C:\Program Files\Microsoft SDKs\Windows\v7.0\bin\rc.exe" /v "{RcFilename}"
cmd /c "("%VS100COMNTOOLS%..\..\VC\bin\vcvars32.bat") &amp;&amp; ("%VS100COMNTOOLS%..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"{DllFilename}" "{ResFilename}")"</pre>
<ol>
<li>UICC.exe (available in Windows 7 SDK) is executed to generate a resource definition script file of the Ribbon XAML</li>
<li>rc.exe (available in Windows 7 SDK) is executed to generate a .res file &#8211; a windows resource file</li>
<li>link.exe (available in Visual Studio 2010 or Visual C++ 2010 Express)) is executed to generate an unmanaged .dll file. This file is the .ribbon file that can be used by Ribbon control!</li>
</ol>
<p>The placeholder in there beginning with an &#8220;{&#8221; are all replaced by the tool. All files that are created will be deleted at the end of the generation process. Only the .ribbon file ({ResFilename} will not be deleted.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=39&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2010/12/10/ribbongenerator-details-windows-ribbon-for-winforms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickstart Tutorial: Windows Ribbon for WinForms</title>
		<link>http://bernhardelbl.wordpress.com/2010/11/17/quickstart-tutorial-windows-ribbon-for-winforms/</link>
		<comments>http://bernhardelbl.wordpress.com/2010/11/17/quickstart-tutorial-windows-ribbon-for-winforms/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 07:43:43 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/?p=10</guid>
		<description><![CDATA[Here I will show you how you can start using the Windows Ribbon from CodePlex. Prepare your developer machine Installation of Windows 7 SDK is required to create and modify the ribbon on a developer machine. 1. Download latest version of RibbonLib from CodePlex You can find the library here: http://windowsribbon.codeplex.com/ 2. Build the RibbonGenerator [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=10&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here I will show you how you can start using the <a href="http://windowsribbon.codeplex.com/" target="_blank">Windows Ribbon </a>from CodePlex.</p>
<p><strong>Prepare your developer machine</strong></p>
<p>Installation of <a title="Windows 7 SDK" href="http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&amp;displaylang=en">Windows 7 SDK</a> is required to create and modify the ribbon on a developer machine.</p>
<p><strong>1. Download latest version of RibbonLib from CodePlex</strong></p>
<p>You can find the library here: <a href="http://windowsribbon.codeplex.com/">http://windowsribbon.codeplex.com/</a></p>
<p><strong>2. Build the RibbonGenerator setup and install it.</strong></p>
<p>Start the Visual Studio 2010 Solution of RibbonGenerator, set the build configuration to Release and build it <strong>twice</strong>!<br />
After the second build it will compile without errors! This is an official Visual Studio 2010 bug and we have to live with it.</p>
<p>.\RibbonLib_v2.6\RibbonGenerator\RibbonGenerator.sln</p>
<p><a href="http://bernhardelbl.files.wordpress.com/2010/11/image-4.png"><img class="alignnone size-full wp-image-13" title="Setup build info and error" src="http://bernhardelbl.files.wordpress.com/2010/11/image-4.png?w=630&#038;h=244" alt="" width="630" height="244" /></a></p>
<p>Now you can install the new setup file that you will find here&#8230;</p>
<p>.\RibbonLib_v2.6\RibbonGenerator\RibbonGenerator.Setup\Release\RibbonGenerator.Setup.msi</p>
<p><strong>3. Compile a Ribbon.dll</strong></p>
<p>To get a compiled version of Ribbon.dll start the sample solution and build it using Visual Studio</p>
<p>.\RibbonLib_v2.6\Ribbon-cs.sln</p>
<p><strong>4. Create a new Windows Forms application containing the Ribbon Control.</strong></p>
<p>Add the Ribbon to your Toolbox doing a right-click on Toolbox / Choose Items<br />
.\RibbonLib_v2.6\Ribbon\bin\Release\Ribbon.dll</p>
<p>Drag/Drop the Ribbon to your form</p>
<p><a href="http://bernhardelbl.files.wordpress.com/2010/11/dragdropribboncontrol.png"><img class="alignnone size-full wp-image-20" title="dragdropribboncontrol" src="http://bernhardelbl.files.wordpress.com/2010/11/dragdropribboncontrol.png?w=630&#038;h=359" alt="" width="630" height="359" /></a></p>
<p>For your body you can add a Panel control and set the DockStyle property to Fill</p>
<p>Add a new Xml file to your Project and rename to Ribbon.xml</p>
<p>Add the following content to the file.</p>
<pre>&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'&gt;
	&lt;Application.Commands&gt;
	&lt;/Application.Commands&gt;

	&lt;Application.Views&gt;

		&lt;Ribbon&gt;
		&lt;/Ribbon&gt;
	&lt;/Application.Views&gt;
&lt;/Application&gt;</pre>
<p>Set the CustomTool of the Ribbon.xml in the File Properties to RibbonGenerator to generate a .ribbon file.<br />
<a href="http://bernhardelbl.files.wordpress.com/2010/11/ribbonxml.png"><img class="alignnone size-full wp-image-21" title="ribbonxml" src="http://bernhardelbl.files.wordpress.com/2010/11/ribbonxml.png?w=630&#038;h=399" alt="" width="630" height="399" /></a><br />
Now you need to specify the .ribbon file in the Ribbon control properties on your form. The name must be the full name including the namespace.<br />
<a href="http://bernhardelbl.files.wordpress.com/2010/11/resourcename.png"><img class="alignnone size-full wp-image-22" title="resourcename" src="http://bernhardelbl.files.wordpress.com/2010/11/resourcename.png?w=630&#038;h=298" alt="" width="630" height="298" /></a></p>
<p>That&#8217;s all. So have a lot of fun playing with the samples included in the download package too.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=10&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2010/11/17/quickstart-tutorial-windows-ribbon-for-winforms/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>

		<media:content url="http://bernhardelbl.files.wordpress.com/2010/11/image-4.png" medium="image">
			<media:title type="html">Setup build info and error</media:title>
		</media:content>

		<media:content url="http://bernhardelbl.files.wordpress.com/2010/11/dragdropribboncontrol.png" medium="image">
			<media:title type="html">dragdropribboncontrol</media:title>
		</media:content>

		<media:content url="http://bernhardelbl.files.wordpress.com/2010/11/ribbonxml.png" medium="image">
			<media:title type="html">ribbonxml</media:title>
		</media:content>

		<media:content url="http://bernhardelbl.files.wordpress.com/2010/11/resourcename.png" medium="image">
			<media:title type="html">resourcename</media:title>
		</media:content>
	</item>
		<item>
		<title>Suppress Warnings for XML comments</title>
		<link>http://bernhardelbl.wordpress.com/2009/02/23/suppress-warnings-for-xml-comments/</link>
		<comments>http://bernhardelbl.wordpress.com/2009/02/23/suppress-warnings-for-xml-comments/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 14:12:29 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/2009/02/23/suppress-warnings-for-xml-comments</guid>
		<description><![CDATA[Here i will show you, how you can suppress warnings for XML comments after a Visual Studio build. Background If you have checked the &#34;XML documentation file&#34; mark in the Visual Studio project settings, a XML file containing all XML comments is created. Additionally you will get a lot of warnings also in designer generated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=3&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!DB54AE2C5D84DB78!272" class="bvMsg">
<p>Here i will show you, how you can suppress warnings for XML comments after a Visual Studio build. </p>
<h2>Background</h2>
<p>If you have checked the &quot;XML documentation file&quot; mark in the Visual Studio project settings, a XML file containing all XML comments is created. Additionally you will get a lot of warnings also in designer generated files, because of the missing or wrong XML comments. While sometimes warnings helps us to improve and stabilize our code, getting hundreds of XML comment warnings is just a pain. </p>
<h2>Warnings</h2>
<p>Missing XML comment for publicly visible type or member &#8230;<br />XML comment on &#8230; has a param tag for &#8216;&#8230;&#8217;, but there is no parameter by that name<br />Parameter &#8216;&#8230;&#8217; has no matching param tag in the XML comment for &#8216;&#8230;&#8217; (but other parameters do)</p>
<h2>Solution</h2>
<p>You can suppress every warning in Visual Studio. </p>
<p>- Right-click the Visual Studio project / Properties / Build Tab </p>
<p>- Insert the following warning numbers in the &quot;Suppress warnings&quot;: 1591,1572,1571,1573,1587,1570</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=3&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2009/02/23/suppress-warnings-for-xml-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP .NET RequiredFieldValidator in Validation Application Block of Enterprise Library 4.0</title>
		<link>http://bernhardelbl.wordpress.com/2008/10/20/asp-net-requiredfieldvalidator-in-validation-application-block-of-enterprise-library-4-0/</link>
		<comments>http://bernhardelbl.wordpress.com/2008/10/20/asp-net-requiredfieldvalidator-in-validation-application-block-of-enterprise-library-4-0/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 13:23:17 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/2008/10/20/asp-net-requiredfieldvalidator-in-validation-application-block-of-enterprise-library-4-0</guid>
		<description><![CDATA[The Validation Application Block included in Enterprise Library 4.0 is a really cool block. I firstly tried to find the RequiredFieldValidator equivalent to ASP .NET. The fact is in the VAB there is only a StringLengthValidator which can be used for this task. There is a possibility to bend this validator to act exactly like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=4&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!DB54AE2C5D84DB78!245" class="bvMsg">
<p>The Validation Application Block included in Enterprise Library 4.0 is a really cool block. I firstly tried to find the RequiredFieldValidator equivalent to ASP .NET. The fact is in the VAB there is only a StringLengthValidator which can be used for this task. There is a possibility to bend this validator to act exactly like the ASP .NET RequiredFieldValidator does. </p>
<p>  </p>
<h2>Configure a &#8216;RequiredFieldValidator&#8217; with Validation Application Block</h2>
<p>1. Use the Configuration Utility to add a StringLengthValidator and rename it to &#8216;Required Validator&#8217;. </p>
<p><a href="http://byfiles.storage.msn.com/y1p50D-3g-aJTjtWt0msd76aBGyXWcmJ-KgO-4avDjWRIuvxOz0mPBwua4epbpOkiqtb1NOvDGP6ko?PARTNER=WRITER"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="310" alt="config" src="http://byfiles.storage.msn.com/y1pPjOZ4RPVVf2vfM964-kbFv9FCpFunBIop4mrD1w6s01qeWLvFFP_k0mXfYtaPWiukgGSHVESX38?PARTNER=WRITER" width="552" border="0" /></a> </p>
<p>2. Configure the StringLengthValidator like in the following way. </p>
<p><a href="http://byfiles.storage.msn.com/y1pELHJniVD9Cuhf1qZSWAIsbaIPRIYkoeH22jZPdJBe-5ainmtG9Rdx6ugtLO1ROi4WaUNiiARKmM?PARTNER=WRITER"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="304" alt="properties" src="http://byfiles.storage.msn.com/y1pZjFjtLgag2F95BO7HU_kzWgndR977HeFo-Ossx8q5Ju859lLcVFa6tE7gq42CtQL3KcP0wFXU1o?PARTNER=WRITER" width="541" border="0" /></a> </p>
<p>  </p>
<h2>Remarks</h2>
<p>You can add an addtional StringLengthValidator to validate for the max length of the string.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=4&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2008/10/20/asp-net-requiredfieldvalidator-in-validation-application-block-of-enterprise-library-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>

		<media:content url="http://byfiles.storage.msn.com/y1pPjOZ4RPVVf2vfM964-kbFv9FCpFunBIop4mrD1w6s01qeWLvFFP_k0mXfYtaPWiukgGSHVESX38?PARTNER=WRITER" medium="image">
			<media:title type="html">config</media:title>
		</media:content>

		<media:content url="http://byfiles.storage.msn.com/y1pZjFjtLgag2F95BO7HU_kzWgndR977HeFo-Ossx8q5Ju859lLcVFa6tE7gq42CtQL3KcP0wFXU1o?PARTNER=WRITER" medium="image">
			<media:title type="html">properties</media:title>
		</media:content>
	</item>
		<item>
		<title>Workaround: The object cannot be added to the ObjectStateManager because it already has an EntityKey. Use ObjectContext.Attach to attach an object that has an existing key.</title>
		<link>http://bernhardelbl.wordpress.com/2008/10/16/workaround-the-object-cannot-be-added-to-the-objectstatemanager-because-it-already-has-an-entitykey-use-objectcontext-attach-to-attach-an-object-that-has-an-existing-key/</link>
		<comments>http://bernhardelbl.wordpress.com/2008/10/16/workaround-the-object-cannot-be-added-to-the-objectstatemanager-because-it-already-has-an-entitykey-use-objectcontext-attach-to-attach-an-object-that-has-an-existing-key/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 13:53:30 +0000</pubDate>
		<dc:creator>Bernhard Elbl</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://bernhardelbl.wordpress.com/2008/10/16/workaround-the-object-cannot-be-added-to-the-objectstatemanager-because-it-already-has-an-entitykey-use-objectcontext-attach-to-attach-an-object-that-has-an-existing-key</guid>
		<description><![CDATA[  I started using the ADO .NET Entity Framework in a new ASP .NET Project. I´m always creating my applications in a multi-layered architecture. The Attach/Detach functionality of EF is the instrument to go here. But soon i got a curious exception while adding a newly created entity that does not exists in the database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=5&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!DB54AE2C5D84DB78!238" class="bvMsg">
<p>  </p>
<p>I started using the ADO .NET Entity Framework in a new ASP .NET Project. I´m always creating my applications in a multi-layered architecture. The Attach/Detach functionality of EF is the instrument to go here. But soon i got a curious exception while adding a newly created entity that does not exists in the database before. </p>
<p><font color="#ff0000">The object cannot be added to the ObjectStateManager because it already has an EntityKey. Use ObjectContext.Attach to attach an object that has an existing key.</font> </p>
<p><a href="http://byfiles.storage.msn.com/y1ppbMdLafwony8Q45ADKaXx_q-MoM2a7fm_8fuKuJe0EviFzcmMn1eu_20hu63XuioycdaOT1WMC4?PARTNER=WRITER"><img style="border-width:0;" height="198" alt="adress_country" src="http://byfiles.storage.msn.com/y1pDnZgImWAHuj_QjfI6RPJPvN4TK8e9_JCrTLcaoqtvvSznkdHTqenNMZoArvsIiBb9e2da3fx_D8?PARTNER=WRITER" width="244" border="0" /></a> </p>
<p>What has happened?<br />Look at this simple EF diagram. We have a Address and a Country entity type. Country contains all countries in the world. Address can be added, modified, and deleted, while Country only will be referenced. </p>
<ul>
<li>Newly created Address
<li>Address references existing Country</li>
</ul>
<p><span style="color:blue;"></span>  </p>
<p>In a multi-layered environment the method to save the address could look like&#8230; </p>
<p><span style="color:blue;">public</span> <span style="color:blue;">void</span> AddAdress(<span style="color:#2b91af;">Address</span> address) </p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<p style="margin:0;">&#123; </p>
<p style="margin:0;">    <span style="color:green;">// Add business rules and validation here&#8230;</span> </p>
<p style="margin:0;">  </p>
<p style="margin:0;">    <span style="color:green;">// Everything is fine, so save the changes now</span> </p>
<p style="margin:0;">    <span style="color:blue;">using</span> (<span style="color:#2b91af;">openorgaEntities</span> context = <span style="color:blue;">new</span> <span style="color:#2b91af;">openorgaEntities</span>()) </p>
<p style="margin:0;">    &#123; </p>
<p style="margin:0;">        context.AddToAddress(address); </p>
<p style="margin:0;">        context.SaveChanges(); </p>
<p style="margin:0;">    &#125; </p>
<p style="margin:0;">&#125;</p>
</p>
</p>
</div>
<p style="margin:0;">
</p>
</div>
<p style="margin:0;">
</div>
<p style="margin:0;">But the AddAddress method will fail and shows the error message as already shown above. </p>
<p style="margin:0;"><font color="#ff0000">The object cannot be added to the ObjectStateManager because it already has an EntityKey. Use ObjectContext.Attach to attach an object that has an existing key.</font> </p>
<p style="margin:0;">  </p>
<p style="margin:0;">After googling the web for more information i found the following post in Microsoft forum. </p>
<p style="margin:0;"><a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3945102&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3945102&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3945102&amp;SiteID=1</a> </p>
<p style="margin:0;">  </p>
<p style="margin:0;">The solutions provided in the post are working, but i feel they are all either bad or only working in specific cases. </p>
<p style="margin:0;">  </p>
<p style="margin:0;">  </p>
<h1>The workaround solution:</h1>
<p style="margin:0;">I wrote an RelationshipManager based helper utility class, that is doing a workaround. Lets take a look to the following illustration. </p>
<p style="margin:0;">  </p>
<p style="margin:0;"><a href="http://dsattq.bay.livefilestore.com/y1pfJsASE1u46Kog9TLeqiLSaSx4ZCKTsJPZswhrB1fa5F4RSh5wri5RGSxZWgg-G9w14TL0OXTG3bRMGzP8rLUJw?PARTNER=WRITER"><img style="border-width:0;" height="72" alt="entityhelperutil_flow" src="http://dsattq.bay.livefilestore.com/y1pkF_NqozI90dLLcK4BV9VAHB43uXTvTwMzXhNFpZBAq-sfVArzejQdDmJYxdVrnArB655a2CkCyLTfKHUveNWHQ?PARTNER=WRITER" width="660" border="0" /></a> </p>
<p style="margin:0;">The workaround is </p>
<ul>
<li>
<div style="margin:0;">to remove all relationships first and remember them,</div>
<li>
<div style="margin:0;">then i add or attach the entity object </div>
<li>
<div style="margin:0;">and in the end i attach every existing related entity object and recreate all relationships.</div>
</li>
</li>
</ul>
<p style="margin:0;">  </p>
<p style="margin:0;"><font color="#ff0000">Note: I assume here that an Entity already having an EntityKey is an existing entity, while all others are newly created entity objects. This may not be true, in all entity models. So please, check if this is the case also in your model!</font> </p>
<p style="margin:0;">  </p>
<h1>Implementation of EntityHelperUtil</h1>
<p style="margin:0;">  </p>
<p style="margin:0;"><a href="http://byfiles.storage.msn.com/y1plRyiXOtBMoES6AH1ZW6gYBdr4BqKzsDL3b2dt1hmFZAvEAV8clJO8O8J0WMFNK6vMBZ56VHMzjY?PARTNER=WRITER"><img style="border-width:0;" height="232" alt="entityhelperutil_cd" src="http://byfiles.storage.msn.com/y1p4ny_ADzAVfZTQXMm6s3qsviidGsdhA7SPtZlalateYv9m4TRyAuOLRZKQGyLyn1UISS0sJZMr28?PARTNER=WRITER" width="244" border="0" /></a> </p>
<p style="margin:0;">The class is having 3 public methods: </p>
<ul>
<li>
<div style="margin:0;">AddObject replaces the ObjectContext.AddObject method</div>
<li>
<div style="margin:0;">Attach replaces the ObjectContext.Attach method</div>
<li>
<div style="margin:0;">AddObjectOrAttach is combination of both</div>
</li>
</ul>
<p style="margin:0;">Additionally the EntityHelperUtil has two methods doing the main work. </p>
<ul>
<li>
<div style="margin:0;">AddRelationships &#8211; Attaches and adds the entity object and every related objects.</div>
<li>
<div style="margin:0;">RemoveRelationships &#8211; Removes every relation between the entity objects.</div>
</li>
</ul>
<h1>Source of EntityHelperUtil.cs</h1>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:blue;">using</span> System; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.ComponentModel; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Collections; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Collections.Generic; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Linq; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Data; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Data.Objects; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Data.Objects.DataClasses; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Text; </p>
<p style="margin:0;"><span style="color:blue;">using</span> System.Reflection; </p>
<p style="margin:0;">  </p>
<p style="margin:0;"><span style="color:blue;">namespace</span> openorga </p>
<p style="margin:0;">&#123; </p>
<p style="margin:0;">    <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">    <span style="color:gray;">///</span><span style="color:green;"> Attach helper for entity framework</span> </p>
<p style="margin:0;">    <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">    <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">EntityHelperUtil</span> </p>
<p style="margin:0;">    &#123; </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> Adds or attaches an entity object to the context</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> AddObjectOrAttach(<span style="color:#2b91af;">ObjectContext</span> context, <span style="color:blue;">string</span> entitySetName, <span style="color:#2b91af;">EntityObject</span> entity) </p>
<p style="margin:0;">        &#123; </p>
<p style="margin:0;">            <span style="color:blue;">if</span> (entity.EntityKey == <span style="color:blue;">null</span>) </p>
<p style="margin:0;">            &#123; </p>
<p style="margin:0;">                AddObject(context, entitySetName, entity); </p>
<p style="margin:0;">            &#125; </p>
<p style="margin:0;">            <span style="color:blue;">else</span> </p>
<p style="margin:0;">            &#123; </p>
<p style="margin:0;">                Attach(context, entity); </p>
<p style="margin:0;">            &#125; </p>
<p style="margin:0;">        &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> Adds an entity object to the context</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> AddObject(<span style="color:#2b91af;">ObjectContext</span> context, <span style="color:blue;">string</span> entitySetName, <span style="color:#2b91af;">IEntityWithRelationships</span> entity) </p>
<p style="margin:0;">        &#123;            </p>
<p style="margin:0;">            <span style="color:green;">// remove all relations</span> </p>
<p style="margin:0;">            <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt; map = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt;(); </p>
<p style="margin:0;">            RemoveRelationships(map, entity, -1); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:green;">// add the entity</span> </p>
<p style="margin:0;">            context.AddObject(entitySetName, entity); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:green;">// recreate all relationships</span> </p>
<p style="margin:0;">            AddRelationships(context, map); </p>
<p style="margin:0;">        &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> Attaches an entity object to the context</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Attach(<span style="color:#2b91af;">ObjectContext</span> context, <span style="color:#2b91af;">EntityObject</span> entity) </p>
<p style="margin:0;">        &#123; </p>
<p style="margin:0;">            <span style="color:green;">// remove all relations</span> </p>
<p style="margin:0;">            <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt; map = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt;(); </p>
<p style="margin:0;">            RemoveRelationships(map, entity, -1); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:green;">// attach the entity </span></p>
<p style="margin:0;">            context.Attach(entity); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:green;">// recreate all relationships</span> </p>
<p style="margin:0;">            AddRelationships(context, map); </p>
<p style="margin:0;">        &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> Attaches all related entity object and recreates all relationships</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:blue;">static</span> <span style="color:blue;">void</span> AddRelationships(<span style="color:#2b91af;">ObjectContext</span> context, <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt; map) </p>
<p style="margin:0;">        &#123; </p>
<p style="margin:0;">            <span style="color:blue;">int</span> layer = -1; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:green;">// loop through all layers</span> </p>
<p style="margin:0;">            <span style="color:blue;">do</span> </p>
<p style="margin:0;">            &#123; </p>
<p style="margin:0;">                layer++; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                <span style="color:green;">// return all entity object from a specific layer</span> </p>
<p style="margin:0;">                <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt; rs = <span style="color:blue;">from</span> r <span style="color:blue;">in</span> map </p>
<p style="margin:0;">                                                      <span style="color:blue;">where</span> r.Layer == layer </p>
<p style="margin:0;">                                                      <span style="color:blue;">select</span> r; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                <span style="color:green;">// check if there are no further related entity objects</span> </p>
<p style="margin:0;">                <span style="color:blue;">if</span> (rs.Count&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt;() == 0) </p>
<p style="margin:0;">                    <span style="color:blue;">break</span>; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                <span style="color:green;">// move through the remembered mappings of the current layer</span> </p>
<p style="margin:0;">                <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">RelationsShipMapping</span> mapping <span style="color:blue;">in</span> rs) </p>
<p style="margin:0;">                &#123; </p>
<p style="margin:0;">                    <span style="color:green;">// check if we need to attach the related entity object</span> </p>
<p style="margin:0;">                    <span style="color:#2b91af;">IEntityWithKey</span> entityWithKey = mapping.TargetEntity <span style="color:blue;">as</span> <span style="color:#2b91af;">IEntityWithKey</span>; </p>
<p style="margin:0;">                    <span style="color:blue;">if</span> (entityWithKey != <span style="color:blue;">null</span> &amp;&amp; entityWithKey.EntityKey != <span style="color:blue;">null</span>) </p>
<p style="margin:0;">                        context.Attach(entityWithKey); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                    <span style="color:green;">// check if it´s a EntityCollection or EntityReference relationship</span> </p>
<p style="margin:0;">                    <span style="color:blue;">if</span> (!mapping.IsReference) </p>
<p style="margin:0;">                    &#123; </p>
<p style="margin:0;">                        <span style="color:green;">// add the related collection entity object</span> </p>
<p style="margin:0;">                        <span style="color:#2b91af;">MethodInfo</span> mi = <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">RelationshipManager</span>).GetMethod(<span style="color:#a31515;">&quot;GetRelatedCollection&quot;</span>).MakeGenericMethod(mapping.TargetEntity.GetType()); </p>
<p style="margin:0;">                        <span style="color:blue;">object</span> col = mi.Invoke( </p>
<p style="margin:0;">                            mapping.Entity.RelationshipManager, </p>
<p style="margin:0;">                            <span style="color:blue;">new</span> <span style="color:blue;">object</span>[]&#123; mapping.RelationshipName, mapping.TargetRole &#125;); </p>
<p style="margin:0;">                        <span style="color:#2b91af;">MethodInfo</span> miAdd = col.GetType().GetMethod(<span style="color:#a31515;">&quot;Add&quot;</span>); </p>
<p style="margin:0;">                        miAdd.Invoke(col, <span style="color:blue;">new</span> <span style="color:blue;">object</span>[] &#123; mapping.TargetEntity &#125;); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                    &#125; </p>
<p style="margin:0;">                    <span style="color:blue;">else</span> </p>
<p style="margin:0;">                    &#123; </p>
<p style="margin:0;">                        <span style="color:green;">// set the related reference entity object</span> </p>
<p style="margin:0;">                        <span style="color:#2b91af;">MethodInfo</span> mi = <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">RelationshipManager</span>).GetMethod(<span style="color:#a31515;">&quot;GetRelatedReference&quot;</span>).MakeGenericMethod(mapping.TargetEntity.GetType()); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        <span style="color:#2b91af;">EntityReference</span> er = (<span style="color:#2b91af;">EntityReference</span>)mi.Invoke( </p>
<p style="margin:0;">                            mapping.Entity.RelationshipManager, </p>
<p style="margin:0;">                            <span style="color:blue;">new</span> <span style="color:blue;">object</span>[]&#123; mapping.RelationshipName, mapping.TargetRole &#125;); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        er.GetType().GetProperty(<span style="color:#a31515;">&quot;Value&quot;</span>).SetValue(er, mapping.TargetEntity, <span style="color:blue;">null</span>); </p>
<p style="margin:0;">                    &#125; </p>
<p style="margin:0;">                &#125; </p>
<p style="margin:0;">            &#125; </p>
<p style="margin:0;">            <span style="color:blue;">while</span> (<span style="color:blue;">true</span>); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">        &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> Removes all related entity objects</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:blue;">static</span> <span style="color:blue;">void</span> RemoveRelationships(<span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">RelationsShipMapping</span>&gt; map, <span style="color:#2b91af;">IEntityWithRelationships</span> entity, <span style="color:blue;">int</span> layer) </p>
<p style="margin:0;">        &#123; </p>
<p style="margin:0;">            <span style="color:green;">// the layer represents the stack in the relationships</span> </p>
<p style="margin:0;">            <span style="color:green;">// for example: the related entities to main entity object is layer 0, </span></p>
<p style="margin:0;">            <span style="color:green;">// and the related entites to the related entites is layer 1, etc&#8230;</span> </p>
<p style="margin:0;">            layer++; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:green;">// get a collection of all related conceptual entities.</span> </p>
<p style="margin:0;">            <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">IRelatedEnd</span>&gt; en = entity.RelationshipManager.GetAllRelatedEnds(); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">            <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">IRelatedEnd</span> end <span style="color:blue;">in</span> en) </p>
<p style="margin:0;">            &#123; </p>
<p style="margin:0;">                <span style="color:green;">// check if the relation is an EntityCollection</span> </p>
<p style="margin:0;">                <span style="color:#2b91af;">IEnumerable</span> col = end <span style="color:blue;">as</span> <span style="color:#2b91af;">IEnumerable</span>; </p>
<p style="margin:0;">                <span style="color:blue;">if</span> (col != <span style="color:blue;">null</span>) </p>
<p style="margin:0;">                &#123; </p>
<p style="margin:0;">                    <span style="color:blue;">string</span> colRelationshipName = (<span style="color:blue;">string</span>)col.GetType().GetProperty(<span style="color:#a31515;">&quot;RelationshipName&quot;</span>).GetValue(col, <span style="color:blue;">null</span>); </p>
<p style="margin:0;">                    <span style="color:blue;">string</span> colSourceRoleName = (<span style="color:blue;">string</span>)col.GetType().GetProperty(<span style="color:#a31515;">&quot;SourceRoleName&quot;</span>).GetValue(col, <span style="color:blue;">null</span>); </p>
<p style="margin:0;">                    <span style="color:blue;">string</span> colTargetRoleName = (<span style="color:blue;">string</span>)col.GetType().GetProperty(<span style="color:#a31515;">&quot;TargetRoleName&quot;</span>).GetValue(col, <span style="color:blue;">null</span>); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                    <span style="color:#2b91af;">IEnumerator</span> enu = col.GetEnumerator(); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                    <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IEntityWithRelationships</span>&gt; mem = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IEntityWithRelationships</span>&gt;(); </p>
<p style="margin:0;">                    <span style="color:blue;">while</span> (enu.MoveNext()) </p>
<p style="margin:0;">                    &#123; </p>
<p style="margin:0;">                        <span style="color:#2b91af;">IEntityWithRelationships</span> item = (<span style="color:#2b91af;">IEntityWithRelationships</span>)enu.Current; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        <span style="color:green;">// check if the relationship is already added the map</span> </p>
<p style="margin:0;">                        <span style="color:blue;">int</span> alreadyExists = (<span style="color:blue;">from</span> c <span style="color:blue;">in</span> map </p>
<p style="margin:0;">                                            <span style="color:blue;">where</span> c.RelationshipName == colRelationshipName &amp;&amp; c.TargetRole == colSourceRoleName </p>
<p style="margin:0;">                                            <span style="color:blue;">select</span> c).Count(); </p>
<p style="margin:0;">                        <span style="color:blue;">if</span> (alreadyExists &gt; 0) </p>
<p style="margin:0;">                            <span style="color:blue;">continue</span>; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        <span style="color:green;">// remember the relationships and add it to the map</span> </p>
<p style="margin:0;">                        <span style="color:#2b91af;">RelationsShipMapping</span> mapping = <span style="color:blue;">new</span> <span style="color:#2b91af;">RelationsShipMapping</span>(); </p>
<p style="margin:0;">                        mapping.Layer = layer; </p>
<p style="margin:0;">                        mapping.RelationshipName = colRelationshipName; </p>
<p style="margin:0;">                        mapping.TargetRole = colTargetRoleName; </p>
<p style="margin:0;">                        mapping.Entity = entity; </p>
<p style="margin:0;">                        mapping.TargetEntity = item; </p>
<p style="margin:0;">                        mapping.IsReference = <span style="color:blue;">false</span>; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        map.Add(mapping); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        mem.Add(item); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        RemoveRelationships(map, item, layer); </p>
<p style="margin:0;">                    &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                    <span style="color:green;">// remove the entity collection relationships</span> </p>
<p style="margin:0;">                    <span style="color:blue;">foreach</span>(<span style="color:#2b91af;">IEntityWithRelationships</span> item <span style="color:blue;">in</span> mem) </p>
<p style="margin:0;">                    &#123; </p>
<p style="margin:0;">                        end.Remove(item); </p>
<p style="margin:0;">                    &#125; </p>
<p style="margin:0;">                &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                <span style="color:green;">// check if the relation is an EntityReference</span> </p>
<p style="margin:0;">                <span style="color:#2b91af;">EntityReference</span> er = end <span style="color:blue;">as</span> <span style="color:#2b91af;">EntityReference</span>; </p>
<p style="margin:0;">                <span style="color:blue;">if</span> (er != <span style="color:blue;">null</span>) </p>
<p style="margin:0;">                &#123; </p>
<p style="margin:0;">                    System.Reflection.<span style="color:#2b91af;">PropertyInfo</span> pValue = er.GetType().GetProperty(<span style="color:#a31515;">&quot;Value&quot;</span>); </p>
<p style="margin:0;">                    <span style="color:#2b91af;">IEntityWithRelationships</span> value = (<span style="color:#2b91af;">IEntityWithRelationships</span>)pValue.GetValue(er, <span style="color:blue;">null</span>); </p>
<p style="margin:0;">                    <span style="color:blue;">if</span> (value == <span style="color:blue;">null</span>) </p>
<p style="margin:0;">                        <span style="color:blue;">continue</span>; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                    <span style="color:blue;">if</span> (er != <span style="color:blue;">null</span>) </p>
<p style="margin:0;">                    &#123; </p>
<p style="margin:0;">                        <span style="color:green;">// check if the reference is already added the map</span> </p>
<p style="margin:0;">                        <span style="color:blue;">int</span> alreadyExists = (<span style="color:blue;">from</span> c <span style="color:blue;">in</span> map </p>
<p style="margin:0;">                                            <span style="color:blue;">where</span> c.RelationshipName == er.RelationshipName &amp;&amp; c.TargetRole == er.SourceRoleName </p>
<p style="margin:0;">                                            <span style="color:blue;">select</span> c).Count(); </p>
<p style="margin:0;">                        <span style="color:blue;">if</span> (alreadyExists &gt; 0) </p>
<p style="margin:0;">                            <span style="color:blue;">continue</span>; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        <span style="color:green;">// remember the relationships and add it to the map</span> </p>
<p style="margin:0;">                        <span style="color:#2b91af;">RelationsShipMapping</span> mapping = <span style="color:blue;">new</span> <span style="color:#2b91af;">RelationsShipMapping</span>(); </p>
<p style="margin:0;">                        mapping.Layer = layer; </p>
<p style="margin:0;">                        mapping.RelationshipName = er.RelationshipName; </p>
<p style="margin:0;">                        mapping.TargetRole = er.TargetRoleName; </p>
<p style="margin:0;">                        mapping.Entity = entity; </p>
<p style="margin:0;">                        mapping.TargetEntity = value; </p>
<p style="margin:0;">                        mapping.IsReference = <span style="color:blue;">true</span>; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        map.Add(mapping); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        <span style="color:green;">// remove the entity reference relationships</span> </p>
<p style="margin:0;">                        pValue.SetValue(er, <span style="color:blue;">null</span>, <span style="color:blue;">null</span>); </p>
<p style="margin:0;">  </p>
<p style="margin:0;">                        RemoveRelationships(map, value, layer); </p>
<p style="margin:0;">                    &#125; </p>
<p style="margin:0;">                &#125; </p>
<p style="margin:0;">            &#125; </p>
<p style="margin:0;">        &#125; </p>
<p style="margin:0;">  </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> Used to remember relationships in the entity object</span> </p>
<p style="margin:0;">        <span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;/summary&gt;</span> </p>
<p style="margin:0;">        <span style="color:blue;">class</span> <span style="color:#2b91af;">RelationsShipMapping</span> </p>
<p style="margin:0;">        &#123; </p>
<p style="margin:0;">            <span style="color:blue;">public</span> <span style="color:blue;">int</span> Layer; </p>
<p style="margin:0;">            <span style="color:blue;">public</span> <span style="color:blue;">string</span> RelationshipName; </p>
<p style="margin:0;">            <span style="color:blue;">public</span> <span style="color:blue;">string</span> TargetRole; </p>
<p style="margin:0;">            <span style="color:blue;">public</span> <span style="color:#2b91af;">IEntityWithRelationships</span> Entity; </p>
<p style="margin:0;">            <span style="color:blue;">public</span> <span style="color:#2b91af;">IEntityWithRelationships</span> TargetEntity; </p>
<p style="margin:0;">            <span style="color:blue;">public</span> <span style="color:blue;">bool</span> IsReference; </p>
<p style="margin:0;">        &#125; </p>
<p style="margin:0;">    &#125; </p>
<p style="margin:0;">&#125;</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</div>
</p>
</p>
</p>
</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bernhardelbl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bernhardelbl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bernhardelbl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bernhardelbl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bernhardelbl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bernhardelbl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bernhardelbl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bernhardelbl.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bernhardelbl.wordpress.com&amp;blog=16199051&amp;post=5&amp;subd=bernhardelbl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bernhardelbl.wordpress.com/2008/10/16/workaround-the-object-cannot-be-added-to-the-objectstatemanager-because-it-already-has-an-entitykey-use-objectcontext-attach-to-attach-an-object-that-has-an-existing-key/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7ea5ec957e54afe787f6af417f65235?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bernhardelbl</media:title>
		</media:content>

		<media:content url="http://byfiles.storage.msn.com/y1pDnZgImWAHuj_QjfI6RPJPvN4TK8e9_JCrTLcaoqtvvSznkdHTqenNMZoArvsIiBb9e2da3fx_D8?PARTNER=WRITER" medium="image">
			<media:title type="html">adress_country</media:title>
		</media:content>

		<media:content url="http://dsattq.bay.livefilestore.com/y1pkF_NqozI90dLLcK4BV9VAHB43uXTvTwMzXhNFpZBAq-sfVArzejQdDmJYxdVrnArB655a2CkCyLTfKHUveNWHQ?PARTNER=WRITER" medium="image">
			<media:title type="html">entityhelperutil_flow</media:title>
		</media:content>

		<media:content url="http://byfiles.storage.msn.com/y1p4ny_ADzAVfZTQXMm6s3qsviidGsdhA7SPtZlalateYv9m4TRyAuOLRZKQGyLyn1UISS0sJZMr28?PARTNER=WRITER" medium="image">
			<media:title type="html">entityhelperutil_cd</media:title>
		</media:content>
	</item>
	</channel>
</rss>
