<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4971377397859266634</id><updated>2024-09-27T08:09:17.965-04:00</updated><category term="aspnet20"/><category term="C#"/><category term="sql2005"/><category term="Continuous Integration"/><category term="SQL2000"/><category term="LINQ"/><category term="PFX"/><category term="XML"/><category term="sharepoint"/><title type='text'>Keeping up with Microsoft.</title><subtitle type='html'>Blogs on code snippets and tools that every &lt;a href=&quot;http://bit.ly/rbgcv&quot;&gt;.NET&lt;/a&gt; developer would need to have on fingerTips...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default?start-index=26&amp;max-results=25'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>74</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4438447017497375229</id><published>2011-02-16T13:33:00.001-05:00</published><updated>2011-02-16T13:33:44.437-05:00</updated><title type='text'>Site Web Analytics not updating Sharepoint 2010</title><content type='html'>&lt;p&gt;If you facing the issue that the web Analytics Reports in Sharepoint 2010 Central Administration is not updating data.   &lt;br /&gt;    &lt;br /&gt;When you go to your site &amp;gt; site settings &amp;gt; Site Web Analytics reports or Site Collection Analytics reports&amp;#160; &lt;br /&gt;You get old data as in the ribbon displayed &amp;quot;Data Last Updated: 12/13/2010 2:00:20 AM&amp;quot;&lt;/p&gt;  &lt;p&gt;Please insure that the following things are covered:   &lt;br /&gt;Insure that &lt;strong&gt;Usage and Data Health Data Collection&lt;/strong&gt; service is configured correctly.     &lt;br /&gt;&lt;strong&gt;Log Collection Schedule&lt;/strong&gt; is configured correctly    &lt;br /&gt;&lt;strong&gt;Microsoft Sharepoint Foundation Usage Data Import&lt;/strong&gt; and &lt;a href=&quot;http://la-p-sharept01:5555/_admin/JobEdit.aspx?JobId=36c67278%2D6c69%2D4c81%2Da1fb%2D4eb51c2672a8&amp;amp;Source=%2F%5Fadmin%2FServiceJobDefinitions%2Easpx&quot;&gt;Microsoft SharePoint Foundation Usage Data Processing&lt;/a&gt; Timer jobs are configured to run at regular intervals    &lt;br /&gt;One last important Timer job is the &lt;a href=&quot;http://la-p-sharept01:5555/_admin/JobEdit.aspx?JobId=2daaa629%2De20b%2D4fd7%2D917e%2D5224f47c603c&amp;amp;Source=%2F%5Fadmin%2FServiceJobDefinitions%2Easpx%3FPageIndex%3D1&quot;&gt;Web Analytics Trigger Workflows Timer Job&lt;/a&gt; insure that this timer job is enabled and scheduled to run at regular intervals (for each site that you need analytics for).    &lt;br /&gt;After you have insured that the web analytics service configuration is working fine and the Usage Data Import job is importing the *.usage files from the ULS LOGS folder into the WSS_Logging database, and that all the required timer jobs are running as expected… &lt;strong&gt;wait for a day&lt;/strong&gt; for the report to get updated… the report gets updated automatically at 2:00 am in the morning… and i could not find a way to control the schedule for this report update job.    &lt;br /&gt;    &lt;br /&gt;So be sure to wait for a day before giving up :)&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4438447017497375229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/4438447017497375229' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4438447017497375229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4438447017497375229'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2011/02/site-web-analytics-not-updating.html' title='Site Web Analytics not updating Sharepoint 2010'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8998704954087497301</id><published>2011-02-04T17:52:00.001-05:00</published><updated>2011-02-16T13:41:32.140-05:00</updated><title type='text'>Change AccountName/LoginName for a SharePoint User (SPUser)</title><content type='html'>&lt;p&gt;Consider the following:    &lt;br /&gt;We have an account named &lt;b&gt;MYDOMAIN\eholz&lt;/b&gt;. This accounts Active Directory Login Name changes to &lt;strong&gt;MYDOMAIN\eburrell      &lt;br /&gt;&lt;/strong&gt;Now this user was a active user in a Sharepoint 2010 team Site, and had a userProfile using the Account name MYDOMAIN\eholz.     &lt;br /&gt;Since the AD LoginName changed to eburrell hence we need to update the Sharepoint User (SPUser object) as well update the userprofile to reflect the new account name.     &lt;br /&gt;To update the Sharepoint User LoginName we can run the following stsadm command on the Server:     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;STSADM –o migrateuser –oldlogin MYDOMAIN\eholz –newlogin MYDOMAIN\eburrell –ignoresidhistory&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;However to update the Sharepoint 2010 UserProfile, i first tried running a Incremental/Full Synchronization using the User Profile Synchronization service… this did not work. To enable me to update the AccountName field (which is a read only field) of the UserProfile, I had to first delete the User Profile for MYDOMAIN\eholz and then run a FULL Synchronization using the User Profile Synchronization service which synchronizes the Sharepoint User Profiles with the AD profiles.&lt;/p&gt;  &lt;p&gt;Update: if you just run the STSADM –o migrateuser command… the profile also gets updated automatically. so all you need is to run the stsadm –o migrate user command and you dont need to delete and recreate the User Profile&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8998704954087497301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/8998704954087497301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8998704954087497301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8998704954087497301'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2011/02/change-accountnameloginname-for.html' title='Change AccountName/LoginName for a SharePoint User (SPUser)'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-282017742525464536</id><published>2010-06-18T12:51:00.001-04:00</published><updated>2010-06-18T12:51:23.857-04:00</updated><title type='text'>Search All Columns in All Tables using TSQL</title><content type='html'>&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;DECLARE @SearchStr nvarchar(100)&lt;br /&gt;&lt;br /&gt;SET @SearchStr = &#39;SEARCH_KEYWORD&#39;&lt;br /&gt;&lt;br /&gt;CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)&lt;br /&gt;SET  @TableName = &#39;&#39;&lt;br /&gt;SET @SearchStr2 = QUOTENAME(&#39;%&#39; + @SearchStr + &#39;%&#39;,&#39;&#39;&#39;&#39;)&lt;br /&gt;&lt;br /&gt;WHILE @TableName IS NOT NULL&lt;br /&gt;BEGIN&lt;br /&gt;	SET @ColumnName = &#39;&#39;&lt;br /&gt;	SET @TableName = &lt;br /&gt;	(&lt;br /&gt;		SELECT MIN(QUOTENAME(TABLE_SCHEMA) + &#39;.&#39; + QUOTENAME(TABLE_NAME))&lt;br /&gt;		FROM 	INFORMATION_SCHEMA.TABLES&lt;br /&gt;		WHERE 		TABLE_TYPE = &#39;BASE TABLE&#39;&lt;br /&gt;			AND	QUOTENAME(TABLE_SCHEMA) + &#39;.&#39; + QUOTENAME(TABLE_NAME) &amp;gt; @TableName&lt;br /&gt;			AND	OBJECTPROPERTY(&lt;br /&gt;					OBJECT_ID(&lt;br /&gt;						QUOTENAME(TABLE_SCHEMA) + &#39;.&#39; + QUOTENAME(TABLE_NAME)&lt;br /&gt;						 ), &#39;IsMSShipped&#39;&lt;br /&gt;					       ) = 0&lt;br /&gt;	)&lt;br /&gt;&lt;br /&gt;	WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)&lt;br /&gt;	BEGIN&lt;br /&gt;		SET @ColumnName =&lt;br /&gt;		(&lt;br /&gt;			SELECT MIN(QUOTENAME(COLUMN_NAME))&lt;br /&gt;			FROM 	INFORMATION_SCHEMA.COLUMNS&lt;br /&gt;			WHERE 		TABLE_SCHEMA	= PARSENAME(@TableName, 2)&lt;br /&gt;				AND	TABLE_NAME	= PARSENAME(@TableName, 1)&lt;br /&gt;				AND	DATA_TYPE IN (&#39;char&#39;, &#39;varchar&#39;, &#39;nchar&#39;, &#39;nvarchar&#39;)&lt;br /&gt;				AND	QUOTENAME(COLUMN_NAME) &amp;gt; @ColumnName&lt;br /&gt;		)&lt;br /&gt;&lt;br /&gt;		IF @ColumnName IS NOT NULL&lt;br /&gt;		BEGIN&lt;br /&gt;			INSERT INTO #Results&lt;br /&gt;			EXEC&lt;br /&gt;			(&lt;br /&gt;				&#39;SELECT &#39;&#39;&#39; + @TableName + &#39;.&#39; + @ColumnName + &#39;&#39;&#39;, LEFT(&#39; + @ColumnName + &#39;, 3630) &lt;br /&gt;				FROM &#39; + @TableName + &#39; (NOLOCK) &#39; +&lt;br /&gt;				&#39; WHERE &#39; + @ColumnName + &#39; LIKE &#39; + @SearchStr2&lt;br /&gt;			)&lt;br /&gt;		END&lt;br /&gt;	END	&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;SELECT ColumnName, ColumnValue FROM #Results&lt;/pre&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/282017742525464536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/282017742525464536' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/282017742525464536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/282017742525464536'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/06/search-all-columns-in-all-tables-using.html' title='Search All Columns in All Tables using TSQL'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-899173764833653493</id><published>2010-06-07T18:54:00.001-04:00</published><updated>2010-06-07T19:05:48.535-04:00</updated><title type='text'>Unit testing internal methods in a strongly named assembly/project</title><content type='html'>&lt;p&gt;If you need create Unit tests for internal methods within a assembly in Visual Studio 2005 or greater, then we need to add an entry in the AssemblyInfo.cs file of the assembly for which you are creating the units tests for. For e.g. if you need to create tests for a assembly named FincadFunctions.dll &amp;amp; this assembly contains internal/friend methods within which need to write unit tests for then we add a entry in the FincadFunctions.dll’s AssemblyInfo.cs file like so : &lt;/p&gt;  &lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&amp;quot;FincadFunctionsTests&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;where FincadFunctionsTests is the name of the Unit Test project which contains the Unit Tests. However if the fincadFunctions.dll is a strongly named assembly then you will the following error when compiling the FincadFunctions.dll assembly : &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Friend assembly reference “FincadFunctionsTests” is invalid. Strong-name assemblies must specify a public key in their InternalsVisibleTo declarations. &lt;br /&gt;  &lt;br /&gt;&lt;/u&gt;Thus to add a public key token to InternalsVisibleTo Declarations do the following: You need the .snk file that was used to strong-name the FincadFunctions.dll assembly. You can extract the public key from this .snk with the sn.exe tool from the .NET SDK. First we extract just the public key from the key pair (.snk) file into another .snk file. &lt;u&gt;sn -p test.snk test.pub&lt;/u&gt; Then we ask for the value of that public key (note we need the long hex key not the short public key token): &lt;u&gt;sn -tp test.pub&lt;/u&gt; We end up getting a super LONG string of hex, but that&#39;s just what we want, the public key value of this key pair. We add it to the strongly named project &amp;quot;FincadFunctions.dll&amp;quot; that we want to expose our internals from. Before what looked like: &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&amp;quot;FincadFunctionsTests&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;Now looks like. &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&amp;quot;FincadFunctionsTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010011fdf2e48bb&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;And we&#39;re done. hope this helps &lt;br /&gt;&lt;br /&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/899173764833653493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/899173764833653493' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/899173764833653493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/899173764833653493'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/06/unit-testing-internal-methods-in.html' title='Unit testing internal methods in a strongly named assembly/project'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1255227718635356709</id><published>2010-05-21T19:40:00.001-04:00</published><updated>2010-05-21T20:00:53.922-04:00</updated><title type='text'>LinqToXML removing empty xmlns attributes</title><content type='html'>Suppose you need to generate the following XML:   &lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;&amp;lt;GenevaLoader xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xsi:schemaLocation=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva masterschema.xsd&amp;quot; xmlns=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;PriceRecords&amp;gt;&lt;br /&gt;    &amp;lt;PriceRecord&amp;gt;&lt;br /&gt;    &amp;lt;/PriceRecord&amp;gt;&lt;br /&gt;  &amp;lt;/PriceRecords&amp;gt;&lt;br /&gt;&amp;lt;/GenevaLoader&amp;gt;&lt;/pre&gt;&lt;br /&gt;Normally you would write the following C# code to accomplish this: &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;const string ns = &amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva&amp;quot;;&lt;br /&gt;XNamespace xnsp = ns;&lt;br /&gt;XNamespace xsi = XNamespace.Get(&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;);&lt;br /&gt;&lt;br /&gt;XElement root = new XElement( xnsp + &amp;quot;GenevaLoader&amp;quot;,  &lt;br /&gt;  new XAttribute(XNamespace.Xmlns + &amp;quot;xsi&amp;quot;, xsi.NamespaceName), &lt;br /&gt;  new XAttribute( xsi + &amp;quot;schemaLocation&amp;quot;, &amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva masterschema.xsd&amp;quot;));&lt;br /&gt;&lt;br /&gt;XElement priceRecords = new XElement(&amp;quot;PriceRecords&amp;quot;);&lt;br /&gt;root.Add(priceRecords);&lt;br /&gt;&lt;br /&gt;	for(int i = 0; i &amp;lt; 3; i++)&lt;br /&gt;	{&lt;br /&gt;	    XElement price = new XElement(&amp;quot;PriceRecord&amp;quot;);&lt;br /&gt;	   priceRecords.Add(price);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	doc.Save(&amp;quot;geneva.xml&amp;quot;);&lt;/pre&gt;&lt;br /&gt;The problem with this approach is that it adds a additional empty xmlns arrtribute on the “PriceRecords” element, like so : &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;&amp;lt;GenevaLoader xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xsi:schemaLocation=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva masterschema.xsd&amp;quot; xmlns=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;PriceRecords xmlns=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;PriceRecord&amp;gt;&lt;br /&gt;    &amp;lt;/PriceRecord&amp;gt;&lt;br /&gt;  &amp;lt;/PriceRecords&amp;gt;&lt;br /&gt;&amp;lt;/GenevaLoader&amp;gt;&lt;/pre&gt;&lt;br /&gt;The solution is to add the xmlns NameSpace in code to each child and grandchild elements of the root element like so : &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;XElement priceRecords = new XElement( xnsp + &amp;quot;PriceRecords&amp;quot;);&lt;br /&gt;root.Add(priceRecords);&lt;br /&gt;&lt;br /&gt;for(int i = 0; i &amp;lt; 3; i++)&lt;br /&gt;{&lt;br /&gt;    XElement price = new XElement(xnsp + &amp;quot;PriceRecord&amp;quot;);&lt;br /&gt;   priceRecords.Add(price);&lt;br /&gt;}&lt;/pre&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1255227718635356709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/1255227718635356709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1255227718635356709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1255227718635356709'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/05/linqtoxml-removing-empty-xmlns.html' title='LinqToXML removing empty xmlns attributes'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6646869720609662987</id><published>2010-05-21T18:46:00.001-04:00</published><updated>2010-05-21T18:46:03.451-04:00</updated><title type='text'>Copying files from GAC using xcopy or Windows Explorer</title><content type='html'>&lt;p&gt;use this command for copying files using a wildcard from the GAC to a local folder.    &lt;br /&gt;xcopy c:\windows\assembly\Microsoft.SqlServer.Smo*.dll c:\gacdll /s/r/y/c     &lt;br /&gt;    &lt;br /&gt;The above command will continue even it encounters any “Access Denied” errors, thus copying over the required files.     &lt;br /&gt;    &lt;br /&gt;To copy files using the Windows explorer just disable the GAC Cache Viewer by adding a entry to the registry:     &lt;br /&gt;Browse to &lt;strong&gt;“HKEY_LOCALMACHINE\Software\Microsoft\Fusion”      &lt;br /&gt;&lt;/strong&gt;Add a Dword called &lt;strong&gt;DisableCacheViewer&lt;/strong&gt;. Set the value of it to &lt;strong&gt;1&lt;/strong&gt;.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6646869720609662987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/6646869720609662987' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6646869720609662987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6646869720609662987'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/05/copying-files-from-gac-using-xcopy-or.html' title='Copying files from GAC using xcopy or Windows Explorer'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4049457182203621155</id><published>2010-05-11T18:50:00.001-04:00</published><updated>2010-05-11T19:05:30.992-04:00</updated><title type='text'>Entity Framework v1 – tips and Tricks Part 3</title><content type='html'>&lt;h5&gt;   &lt;br /&gt;&lt;/h5&gt;  &lt;p&gt;The previous posts on Entity framework are available here :    &lt;br /&gt;&lt;a href=&quot;http://geekswithblogs.net/rgupta/archive/2010/04/01/entity-framework-version-1---brief-synopsis-and-tips-ndash.aspx&quot;&gt;Entity Framework version 1- Brief Synopsis and Tips – Part 1&lt;/a&gt;     &lt;br /&gt;&lt;a href=&quot;http://geekswithblogs.net/rgupta/archive/2010/04/13/entity-framework-v1-hellip-brief-synopsis-and-tips-ndash-part.aspx&quot;&gt;Entity Framework v1 … Brief Synopsis and Tips – Part 2&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;&lt;u&gt;General Tips on Entity Framework v1 &amp;amp; Linq to Entities: &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ToTraceString()&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;If you need to know the underlying SQL that the EF generates for a Linq To Entities query, then use the ToTraceString() method of the ObjectQuery class. (or use &lt;strong&gt;&lt;u&gt;LINQPAD&lt;/u&gt;&lt;/strong&gt;)     &lt;br /&gt;Note that you need to cast the LINQToEntities query to ObjectQuery before calling TotraceString() as follows:&lt;/p&gt;  &lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;string efSQL = ((ObjectQuery)from c in ctx.Contact&lt;br /&gt;         where c.Address.Any(a =&amp;gt; a.CountryRegion == &amp;quot;US&amp;quot;)&lt;br /&gt;         select c.ContactID).ToTraceString();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;======================================================================&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;MARS or MultipleActiveResultSet &lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;When you create a EDM Model (EDMX file) from the database using Visual Studio, it generates a connection string with the same name as the name of the EntityContainer in CSDL. In the ConnectionString so generated it sets the MultipleActiveResultSet attribute to true by default. So if you are running the following query then it streams multiple readers over the same connection:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;using (BAEntities context = new BAEntities())&lt;br /&gt;{&lt;br /&gt;  var cons =&lt;br /&gt;      from con in context.Contacts&lt;br /&gt;      where con.FirstName == &amp;quot;Jose&amp;quot;&lt;br /&gt;      select con;&lt;br /&gt;  foreach (var c in cons)&lt;br /&gt;  {&lt;br /&gt;    if (c.AddDate &amp;lt; new System.DateTime(2007, 1, 1))&lt;br /&gt;    {&lt;br /&gt;      c.Addresses.Load();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;====================================================================== &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Explicitly opening and closing EntityConnection&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When you call ToList() or foreach on a LINQToEntities query the EF automatically closes the connection after all the records from the query have been consumed. &lt;br /&gt;  &lt;br /&gt;Thus if you need to run many LINQToEntities queries over the same connection then explicitly open and close the connection as follows:&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;using (BAEntities context = new BAEntities())&lt;br /&gt;{&lt;br /&gt;  context.Connection.Open();&lt;br /&gt;  var cons = from con in context.Contacts where con.FirstName == &amp;quot;Jose&amp;quot;&lt;br /&gt;             select con;&lt;br /&gt;  var conList = cons.ToList();&lt;br /&gt;  var allCustomers =  from con in context.Contacts.OfType&amp;lt;Customer&amp;gt;()&lt;br /&gt;                      select con;&lt;br /&gt;  var allcustList = allCustomers.ToList();&lt;br /&gt;  context.Connection.Close();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;====================================================================== &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Dispose ObjectContext only if required &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;After you retrieve entities using the ObjectContext and you are not explicitly disposing the ObjectContext then insure that your code &lt;strong&gt;&lt;u&gt;does&lt;/u&gt;&lt;/strong&gt; consume all the records from the LinqToEntities query by calling .ToList() or foreach statement, otherwise the the database connection will remain open and will be closed by the garbage collector when it gets to dispose the ObjectContext. &lt;br /&gt;  &lt;br /&gt;Secondly if you are making updates to the entities retrieved using LinqToEntities then insure that you dont inadverdently dispose of the ObjectContext after the entities are retrieved and before calling .SaveChanges() since you need the SAME ObjectContext to keep track of changes made to the Entities (by using ObjectStateEntry objects). So if you do need to explicitly dispose of the ObjectContext do so only after calling SaveChanges() and only if you &lt;strong&gt;&lt;u&gt;dont &lt;/u&gt;&lt;/strong&gt;need to change track the entities retrieved any further. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;======================================================================&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;SQL InjectionAttacks under control with EFv1 &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;LinqToEntities and LinqToSQL queries are parameterized before they are sent to the DB hence they are not vulnerable to SQL Injection attacks. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;EntitySQL may be slightly vulnerable to attacks since it does not use parameterized queries. However since the EntitySQL demands that the query be valid Entity SQL syntax and valid native SQL syntax at the same time. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;So the only way one can do a SQLInjection Attack is by knowing the SSDL of the EDM Model and be able to write the correct EntitySQL (note one cannot append regular SQL since then the query wont be a valid EntitySQL syntax) and append it to a parameter. &lt;br /&gt;&lt;br /&gt;====================================================================== &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Improving Performance&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;You can convert the EntitySets and AssociationSets in a EDM Model into precompiled Views using the edmgen utility. for e.g. the Customer Entity can be converted into a precompiled view using edmgen and all LinqToEntities query against the contaxt.Customer EntitySet will use the precompiled View instead of the EntitySet itself (the same being true for relationships (EntityReference &amp;amp; EntityCollections of a Entity)). The advantage being that when using precompiled views the performance will be much better. &lt;br /&gt;  &lt;br /&gt;The syntax for generating precompiled views for a existing EF project is : &lt;br /&gt;&lt;u&gt;edmgen /mode:ViewGeneration /inssdl:BAModel.ssdl /incsdl:BAModel.csdl /inmsl:BAModel.msl /p:Chap14.csproj &lt;br /&gt;&lt;/u&gt;Note that this will only generate precompiled views for EntitySets and Associations and not for existing LinqToEntities queries in the project.(for that use CompiledQuery.Compile&amp;lt;&amp;gt;) &lt;br /&gt;Secondly if you have a LinqToEntities query that you need to &lt;strong&gt;&lt;u&gt;run multiple times&lt;/u&gt;&lt;/strong&gt;, then one should precompile the query using CompiledQuery.Compile method. The CompiledQuery.Compile&amp;lt;&amp;gt; method accepts a lamda expression as a parameter, which denotes the LinqToEntities query&amp;#160; that you need to precompile. &lt;br /&gt;&lt;br /&gt;The following is a example of a lamda that we can pass into the CompiledQuery.Compile() method&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;Expression&amp;lt;Func&amp;lt;BAEntities, string, IQueryable&amp;lt;Customer&amp;gt;&amp;gt;&amp;gt; expr = (BAEntities ctx1, string loc) =&amp;gt;&lt;br /&gt;                    from c in ctx1.Contacts.OfType&amp;lt;Customer&amp;gt;()&lt;br /&gt;                    where c.Reservations.Any(r =&amp;gt; r.Trip.Destination.DestinationName == loc)&lt;br /&gt;                    select c;&lt;/pre&gt;Then we call the Compiled Query as follows:&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;var query = CompiledQuery.Compile&amp;lt;BAEntities, string, IQueryable&amp;lt;Customer&amp;gt;&amp;gt;(expr);&lt;br /&gt;&lt;br /&gt;using (BAEntities ctx = new BAEntities())&lt;br /&gt;{&lt;br /&gt;    var loc = &amp;quot;Malta&amp;quot;;&lt;br /&gt;    IQueryable&amp;lt;Customer&amp;gt; custs = query.Invoke(ctx, loc);&lt;br /&gt;    var custlist = custs.ToList();&lt;br /&gt;    foreach (var item in custlist)&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(item.FullName);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;Note that if you created a ObjectQuery or a Enitity SQL query instead of the LINQToEntities query, you dont need precompilation for e.g.&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;An Example of EntitySQL query :&lt;br /&gt;string esql = &amp;quot;SELECT VALUE c from Contacts AS c where c is of(BAGA.Customer) and c.LastName = &#39;Gupta&#39;&amp;quot;;&lt;br /&gt;ObjectQuery&amp;lt;Customer&amp;gt; custs = CreateQuery&amp;lt;Customer&amp;gt;(esql);&lt;br /&gt;&lt;br /&gt;An Example of ObjectQuery built using ObjectBuilder methods:&lt;br /&gt;from c in Contacts.OfType&amp;lt;Customer&amp;gt;().Where(&amp;quot;it.LastName == &#39;Gupta&#39;&amp;quot;)&lt;br /&gt;select c&lt;/pre&gt;&lt;br /&gt;This is since the Query plan is cached and thus the performance improves a bit, however since the ObjectQuery or EntitySQL query still needs to materialize the results into Entities hence it will take the same amount of performance hit as with LinqToEntities. &lt;br /&gt;  &lt;br /&gt;However note that &lt;strong&gt;&lt;u&gt;not&lt;/u&gt;&lt;/strong&gt; ALL EntitySQL based or QueryBuilder based ObjectQuery plans are cached. So if you are in doubt always create a LinqToEntities compiled query and use that instead &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;============================================================ &lt;br /&gt;&lt;strong&gt;&lt;u&gt;GetObjectStateEntry Versus GetObjectByKey &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;We can get to the Entity being referenced by the ObjectStateEntry via its Entity property and there are helper methods in the ObjectStateManager (osm.TryGetObjectStateEntry) to get the ObjectStateEntry for a entity (for which we know the EntityKey). Similarly The ObjectContext has helper methods to get an Entity i.e. TryGetObjectByKey(). &lt;br /&gt;&lt;br /&gt;TryGetObjectByKey() uses &lt;tt&gt;GetObjectStateEntry&lt;/tt&gt;&lt;a name=&quot;the&quot;&gt;&lt;/a&gt; method under the covers to find the object, however One important difference between these 2 methods is that &lt;tt&gt;TryGetObjectByKey&lt;/tt&gt;&lt;a name=&quot;if it&quot;&gt;&lt;/a&gt; queries the database if it is unable to find the object in the context, whereas &lt;tt&gt;TryGetObjectStateEntry&lt;/tt&gt;&lt;a name=&quot;in the&quot;&gt;&lt;/a&gt; only looks in the context for existing entries. It will not make a trip to the database&lt;br /&gt;============================================================= &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;&lt;u&gt;POCO objects with EFv1:&lt;/u&gt;&lt;/strong&gt; &lt;br /&gt;To create POCO objects that can be used with EFv1. We need to implement 3 key interfaces: &lt;br /&gt;&lt;br /&gt;IEntityWithKey &lt;br /&gt;IEntityWithRelationships &lt;br /&gt;IEntityWithChangeTracker &lt;br /&gt;  &lt;br /&gt;Implementing IEntityWithKey is not mandatory, but if you dont then we need to explicitly provide values for the EntityKey for various functions (for e.g. the functions needed to implement IEntityWithChangeTracker and IEntityWithRelationships). &lt;br /&gt;&lt;br /&gt;Implementation of IEntityWithKey involves exposing a property named EntityKey which returns a EntityKey object. &lt;br /&gt;Implementation of IEntityWithChangeTracker involves implementing a method named SetChangeTracker since there can be multiple changetrackers (Object Contexts) existing in memory at the same time.&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;public void SetChangeTracker(IEntityChangeTracker changeTracker)&lt;br /&gt;{&lt;br /&gt;  _changeTracker = changeTracker;&lt;br /&gt;}&lt;/pre&gt;Additionally each property in the POCO object needs to notify the changetracker (objContext) that it is updating itself by calling the &lt;tt&gt;EntityMemberChanged&lt;/tt&gt; and &lt;tt&gt;EntityMemberChanging&lt;/tt&gt; methods on the changeTracker. for e.g.:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;public EntityKey EntityKey&lt;br /&gt;{&lt;br /&gt;  get { return _entityKey; }&lt;br /&gt;  set&lt;br /&gt;  {&lt;br /&gt;    if (_changeTracker != null)&lt;br /&gt;    {&lt;br /&gt;       _changeTracker.EntityMemberChanging(&amp;quot;EntityKey&amp;quot;);&lt;br /&gt;       _entityKey = value;&lt;br /&gt;       _changeTracker.EntityMemberChanged(&amp;quot;EntityKey&amp;quot;);&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;       _entityKey = value;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;=====================  Custom Property  ====================================&lt;br /&gt;&lt;br /&gt;[EdmScalarPropertyAttribute(IsNullable = false)]&lt;br /&gt;public System.DateTime OrderDate&lt;br /&gt;{&lt;br /&gt;  get { return _orderDate; }&lt;br /&gt;  set&lt;br /&gt;  {&lt;br /&gt;    if (_changeTracker != null)&lt;br /&gt;    {&lt;br /&gt;      _changeTracker.EntityMemberChanging(&amp;quot;OrderDate&amp;quot;);&lt;br /&gt;      _orderDate = value;&lt;br /&gt;      _changeTracker.EntityMemberChanged(&amp;quot;OrderDate&amp;quot;);&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;      _orderDate = value;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;Finally you also need to create the EntityState property as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;public EntityState EntityState&lt;br /&gt;{&lt;br /&gt;  get  { return _changeTracker.EntityState;  }&lt;br /&gt;}&lt;/pre&gt;The IEntityWithRelationships involves creating a property that returns RelationshipManager object:&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;public RelationshipManager RelationshipManager&lt;br /&gt;{&lt;br /&gt;  get&lt;br /&gt;  {&lt;br /&gt;    if (_relManager == null)&lt;br /&gt;      _relManager = RelationshipManager.Create(this);&lt;br /&gt;    return _relManager;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;============================================================ &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Tip : ProviderManifestToken – change EDMX File to use SQL 2008 instead of SQL 2005 &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;To use with SQL Server 2008, edit the EDMX file (the raw XML) changing the ProviderManifestToken in the SSDL attributes from &amp;quot;2005&amp;quot; to &amp;quot;2008&amp;quot; &lt;br /&gt;============================================================= &lt;br /&gt;With EFv1 we cannot use Structs to replace a anonymous Type while doing projections in a LINQ to Entities query. While the same is supported with LINQToSQL, it is not with LinqToEntities. For e.g. the following is &lt;strong&gt;&lt;u&gt;not&lt;/u&gt;&lt;/strong&gt; supported with LinqToEntities since only parameterless constructors and initializers are supported in LINQ to Entities. (the same works with LINQToSQL)&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;cpp&quot; ?=&quot;?&quot; name=&quot;code&quot;&gt;public struct CompanyInfo&lt;br /&gt;{&lt;br /&gt;    public int ID { get; set; }&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;}&lt;br /&gt;var companies = (from c in dc.Companies&lt;br /&gt;            where c.CompanyIcon == null&lt;br /&gt;             select new CompanyInfo { Name = c.CompanyName, ID = c.CompanyId }).ToList(); ;&lt;/pre&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4049457182203621155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/4049457182203621155' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4049457182203621155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4049457182203621155'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/05/entity-framework-v1-tips-and-tricks_11.html' title='Entity Framework v1 – tips and Tricks Part 3'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8813088957843158621</id><published>2009-12-14T16:57:00.002-05:00</published><updated>2009-12-14T17:00:14.550-05:00</updated><title type='text'>Split SQL 2005 column values into multiple rows</title><content type='html'>&lt;p&gt;Suppose that you have a column that stored multiple values in a single row using some delimiter as ‘,’.  Now you are tasked with splitting these values into a separate row for each value and you need to do this on multiple rows in the table. &lt;/p&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot; id=&quot;codeSnippet&quot;   &gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum1&quot;  style=&quot;color:#606060;&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;distinct&lt;/span&gt; r.items&lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum2&quot;  style=&quot;color:#606060;&quot;&gt;   2:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;Order&lt;/span&gt; o&lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum3&quot;  style=&quot;color:#606060;&quot;&gt;   3:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;cross&lt;/span&gt; apply dbo.split(o.Products,&lt;span style=&quot;color:#006080;&quot;&gt;&#39;,&#39;&lt;/span&gt;) r&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Here the Order Table has a Products column that has multiple Products stored in a single column separated with commas like ‘Tea,Coffee’ associated with a single Order. What the above query does is it gives a distinct list of names of all Products stored in all rows in the Order table. The Split() is a UDF which splits the string into one row for each value&lt;/p&gt;&lt;p&gt;Similarly if you need to check if these multiple values stored in the Products column contain a particular string from a list of values, i,e,&lt;/p&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot; id=&quot;codeSnippet&quot;   &gt;&lt;br /&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum1&quot;  style=&quot;color:#606060;&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;select&lt;/span&gt; o.* &lt;span style=&quot;color:#0000ff;&quot;&gt;from&lt;/span&gt; Company c&lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum2&quot;  style=&quot;color:#606060;&quot;&gt;   2:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;join&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;Order&lt;/span&gt; o &lt;span style=&quot;color:#0000ff;&quot;&gt;on&lt;/span&gt; c.ItemID = o.companyItemID&lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum3&quot;  style=&quot;color:#606060;&quot;&gt;   3:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;where&lt;/span&gt; (&lt;span style=&quot;color:#0000ff;&quot;&gt;select&lt;/span&gt; * &lt;span style=&quot;color:#0000ff;&quot;&gt;from&lt;/span&gt; dbo.split(o.Products) &lt;span style=&quot;color:#0000ff;&quot;&gt;in&lt;/span&gt; (&lt;span style=&quot;color:#006080;&quot;&gt;&#39;TBD&#39;&lt;/span&gt;,&lt;span style=&quot;color:#006080;&quot;&gt;&#39;Tea&#39;&lt;/span&gt;, &lt;span style=&quot;color:#006080;&quot;&gt;&#39;Coffee&#39;&lt;/span&gt;))&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Since the above would not compile hence the right solution to do something like this would be:&lt;/p&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot; id=&quot;codeSnippet&quot;   &gt;&lt;br /&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum1&quot;  style=&quot;color:#606060;&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;select&lt;/span&gt; o.* &lt;span style=&quot;color:#0000ff;&quot;&gt;from&lt;/span&gt; Company c&lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum2&quot;  style=&quot;color:#606060;&quot;&gt;   2:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;join&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;Order&lt;/span&gt; o &lt;span style=&quot;color:#0000ff;&quot;&gt;on&lt;/span&gt; c.ItemID = o.companyItemID&lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum3&quot;  style=&quot;color:#606060;&quot;&gt;   3:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;cross&lt;/span&gt; apply dbo.Split(Products,&lt;span style=&quot;color:#006080;&quot;&gt;&#39;,&#39;&lt;/span&gt;) p &lt;/pre&gt;&lt;pre style=&quot;BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:&#39;Courier New&#39;, courier, monospace;font-size:8pt;color:black;&quot;   &gt;&lt;span id=&quot;lnum4&quot;  style=&quot;color:#606060;&quot;&gt;   4:&lt;/span&gt; &lt;span style=&quot;color:#0000ff;&quot;&gt;where&lt;/span&gt; p.Items &lt;span style=&quot;color:#0000ff;&quot;&gt;in&lt;/span&gt; (&lt;span style=&quot;color:#006080;&quot;&gt;&#39;TBD&#39;&lt;/span&gt;,&lt;span style=&quot;color:#006080;&quot;&gt;&#39;Tea&#39;&lt;/span&gt;,&lt;span style=&quot;color:#006080;&quot;&gt;&#39;Coffee&#39;&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;what we are doing here is a inner join on the Split() table valued UDF which returns a table containing one row for each value split and then comparing each Item to see if it matches one of the product names i.e. Tea or Coffee.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8813088957843158621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/8813088957843158621' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8813088957843158621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8813088957843158621'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/12/split-sql-2005-column-values-into.html' title='Split SQL 2005 column values into multiple rows'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2169214838465405114</id><published>2009-03-06T17:32:00.001-05:00</published><updated>2009-03-06T17:32:41.694-05:00</updated><title type='text'>Dispose and Finalize methods and .NET Memory optimizations</title><content type='html'>&lt;p&gt;I have jotted down a few points on implementing the IDisposable and Finalize patterns in .NET.&lt;/p&gt;  &lt;p&gt;Please find it here : &lt;a target=&quot;_blank&quot; href=&quot;http://geekswithblogs.net/rgupta/archive/2009/03/06/dispose-and-finalize-methods.aspx&quot;&gt;Dispose and Finalize methods&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I also jotted down some .net Memory Optimization tips: Please find them here : &lt;a target=&quot;_blank&quot; href=&quot;http://geekswithblogs.net/rgupta/archive/2009/03/06/some-tips-on-.net-memory-usage.aspx&quot;&gt;Some Tips on .NET Memory optimizations&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2169214838465405114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/2169214838465405114' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2169214838465405114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2169214838465405114'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/03/dispose-and-finalize-methods-and-net.html' title='Dispose and Finalize methods and .NET Memory optimizations'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4264128135865972160</id><published>2009-03-03T19:57:00.001-05:00</published><updated>2009-03-03T19:57:00.509-05:00</updated><title type='text'>Creating dynamically generated logfiles with log4net</title><content type='html'>&lt;p&gt;If you need to generate logfile names dynmically when using log4net then we can do this using the log4net Properties.&lt;/p&gt;  &lt;p&gt;To learn more on this please visit : &lt;a target=&quot;_blank&quot; href=&quot;http://geekswithblogs.net/rgupta/archive/2009/03/03/dynamic-log-filenames-with-log4net.aspx&quot;&gt;creating dynamic logfile names with log4net&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4264128135865972160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/4264128135865972160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4264128135865972160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4264128135865972160'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/03/creating-dynamically-generated-logfiles.html' title='Creating dynamically generated logfiles with log4net'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1205303643478543223</id><published>2009-03-03T18:55:00.001-05:00</published><updated>2009-03-03T18:55:55.929-05:00</updated><title type='text'>Tips on using log4net RollingFileAppender</title><content type='html'>&lt;p&gt;I have compiled a list of useful properties that you can set on the RollingFileAppender in the log4net XML config file which can determine the order in which log file backups will be generated, whether they will rollover based on dates or size or both.&lt;/p&gt;  &lt;p&gt;For more information please check this link out : &lt;a target=&quot;_blank&quot; href=&quot;http://geekswithblogs.net/rgupta/archive/2009/03/03/tips-on-using-log4net-rollingfileappender.aspx&quot;&gt;Tips on using log4net RollingFileAppender&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1205303643478543223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/1205303643478543223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1205303643478543223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1205303643478543223'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/03/tips-on-using-log4net.html' title='Tips on using log4net RollingFileAppender'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1827192027572300480</id><published>2009-01-28T20:06:00.002-05:00</published><updated>2010-05-11T17:48:25.945-04:00</updated><title type='text'>ConfigSectionHandler for Hierarchical configs</title><content type='html'>Here is a quick way to create a ConfigSection Handler for reading Hierarchical configs.  For e.g. suppose you need to read a config file which has the following structure:  &lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt;&lt;br /&gt;&lt;mainconfig&gt;&lt;company&gt;MySpace&lt;/company&gt;&lt;br /&gt; &lt;subconfig&gt;&lt;br /&gt;  &lt;id&gt;23&lt;/id&gt;&lt;br /&gt;   &lt;firstname&gt;Rohit&lt;/firstname&gt;&lt;br /&gt;  &lt;lastname&gt;Gupta&lt;/lastname&gt;&lt;br /&gt;  &lt;/subconfig&gt;&lt;br /&gt;&lt;/mainconfig&gt;&lt;br /&gt;&lt;/pre&gt;For this you would create the 2 classes, one for the Parent Config and another for the chold config like this:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt;&lt;br /&gt;  [XmlRoot(&quot;MainConfig&quot;)]&lt;br /&gt;   public class MainConfig&lt;br /&gt;   {&lt;br /&gt;       private static readonly MainConfig instance =&lt;br /&gt; (MainConfig)ConfigurationManager.GetSection(&quot;MainConfig&quot;);&lt;br /&gt;       public static MainConfig GetInstance()&lt;br /&gt;       {&lt;br /&gt;           if (instance == null)&lt;br /&gt;               throw new ConfigurationErrorsException(&lt;br /&gt;                   &quot;Unable to locate or deserialize the &#39;MainConfig&#39; section.&quot;);&lt;br /&gt;&lt;br /&gt;           return instance;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       public string Company { get; set; }&lt;br /&gt;&lt;br /&gt;       public SubConfig FriendsConfig { get; set; }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   [XmlRoot(&quot;SubConfig&quot;)]&lt;br /&gt;   public class SubConfig&lt;br /&gt;   {&lt;br /&gt;       public int ID { get; set; }&lt;br /&gt;       public string Name { get; set; }&lt;br /&gt;       public string LastName { get; set; }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then you would create a configsectionHandler class which reads the config from the .config file:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt;&lt;br /&gt;&lt;br /&gt;public class MainConfigSectionHandler : IConfigurationSectionHandler&lt;br /&gt;   {&lt;br /&gt;       #region IConfigurationSectionHandler Members&lt;br /&gt;&lt;br /&gt;       public object Create(object parent, object configContext, System.Xml.XmlNode section)&lt;br /&gt;       {&lt;br /&gt;           MainConfig typedConfig = GetConfig&lt;mainconfig&gt;(section);&lt;br /&gt;&lt;br /&gt;           if (typedConfig != null)&lt;br /&gt;           {&lt;br /&gt;               #region Get Sub Configs&lt;br /&gt;               foreach (XmlNode node in section.ChildNodes)&lt;br /&gt;               {&lt;br /&gt;                   switch (node.Name)&lt;br /&gt;                   {&lt;br /&gt;                       case &quot;SubConfig&quot;:&lt;br /&gt;                           SubConfig friendsConfig = GetConfig&lt;subconfig&gt;(node);&lt;br /&gt;                           typedConfig.FriendsConfig = friendsConfig;&lt;br /&gt;                           break;&lt;br /&gt;                       default:&lt;br /&gt;                           break;&lt;br /&gt;                   }&lt;br /&gt;               }&lt;br /&gt;               #endregion&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;           return typedConfig;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       public T GetConfig&lt;t&gt;(System.Xml.XmlNode section) where T : class&lt;br /&gt;       {&lt;br /&gt;           T sourcedObject = default(T);&lt;br /&gt;           Type t = typeof(T);&lt;br /&gt;           XmlSerializer ser = new XmlSerializer(typeof(T));&lt;br /&gt;           sourcedObject = ser.Deserialize(new XmlNodeReader(section)) as T;&lt;br /&gt;           return sourcedObject;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       #endregion&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;/t&gt;&lt;/subconfig&gt;&lt;/mainconfig&gt;&lt;/pre&gt;&lt;br /&gt;After this you would add a entry in the app.config for this configsection Handler as the following:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt;&lt;br /&gt; &lt;configsections&gt;&lt;br /&gt;  &lt;section name=&quot;MainConfig&quot; type=&quot;App.MainConfigSectionHandler,App&quot;&gt;&lt;br /&gt; &lt;/section&gt;&lt;br /&gt;&lt;/configsections&gt;&lt;/pre&gt;&lt;br /&gt;Finally to read this config, you would write the following:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt;&lt;br /&gt;MainConfig config = MainConfig.GetInstance(); Console.WriteLine(config.Company);&lt;br /&gt;Console.WriteLine(config.FriendsConfig.ID);&lt;br /&gt;Console.WriteLine(config.FriendsConfig.LastName);&lt;br /&gt;Console.WriteLine(config.FriendsConfig.Name);&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1827192027572300480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/1827192027572300480' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1827192027572300480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1827192027572300480'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/01/configsectionhandler-for-hierarchical.html' title='ConfigSectionHandler for Hierarchical configs'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4350966255596572413</id><published>2009-01-07T21:45:00.004-05:00</published><updated>2009-01-11T04:12:28.993-05:00</updated><title type='text'>Lucene: Multifield searches</title><content type='html'>&lt;p&gt;We can run multifield searches in Lucene using either the BooleanQuery API or using the MultiFieldQueryParser for parsing the query text. For e.g. If a index has 2 fields FirstName and LastName and if you need to search for &quot;John&quot; in the FirstName field and &quot;Travis&quot; in the LastName field one can use a Boolean Query as such: &lt;/p&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;&lt;br /&gt;BooleanQuery bq = new BooleanQuery();&lt;br /&gt;Query qf = new TermQuery(new Lucene.Net.Index.Term(&quot;FirstName&quot;, &quot;John&quot;));&lt;br /&gt;Query ql = new TermQuery(new Lucene.Net.Index.Term(&quot;LastName&quot;, &quot;Travis&quot;));&lt;br /&gt;bq.Add(qf, BooleanClause.Occur.MUST);&lt;br /&gt;bq.Add(ql, BooleanClause.Occur.MUST);&lt;br /&gt;IndexSearcher srchr = new IndexSearcher(@&quot;C:\indexDir&quot;);&lt;br /&gt;srchr.Search(bq);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; Now if we need to search a single term across either of the FirstName and LastName fields then we can use the MultiFieldQueryParser as follows:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;&lt;br /&gt;Query query = MultiFieldQueryParser.parse(&quot;commonName&quot;,&lt;br /&gt;new String[] { &quot;FirstName&quot;, &quot;LastName&quot; },&lt;br /&gt;new SimpleAnalyzer());&lt;br /&gt;srchr.Search(query);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; Now if you need to search the term that must exist in both the fields then we use the following:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;&lt;br /&gt; Query query = MultiFieldQueryParser.Parse(&quot;commonName&quot;,&lt;br /&gt;new String[] { &quot;FirstName&quot;, &quot;LastName&quot; },&lt;br /&gt;new BooleanClause.Occur[] { BooleanClause.Occur.MUST,BooleanClause.Occur.MUST}&lt;br /&gt;, new SimpleAnalyzer());&lt;br /&gt;srchr.Search(query);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; Finally if you don’t want a term to occur in one of the Fields (say FirstName) then use:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;&lt;br /&gt; Query query = MultiFieldQueryParser.Parse(&quot;commonName&quot;,&lt;br /&gt;new String[] { &quot;FirstName&quot;, &quot;LastName&quot; },&lt;br /&gt;new BooleanClause.Occur[] { BooleanClause.Occur.MUST_NOT,BooleanClause.Occur.MUST},&lt;br /&gt;new SimpleAnalyzer());&lt;br /&gt;srchr.Search(query);  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; &lt;div&gt;so if you need to search a single term across multiple fields then use MultiFieldQueryParser, if you need to search different terms in different fields then use the BooleanQuery as shown first&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4350966255596572413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/4350966255596572413' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4350966255596572413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4350966255596572413'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/01/lucene-multifield-searches.html' title='Lucene: Multifield searches'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5511951365340036793</id><published>2008-12-01T12:59:00.001-05:00</published><updated>2008-12-01T13:04:50.963-05:00</updated><title type='text'>Dynamically creating types using reflection and setting properties using Reflection.Emit.</title><content type='html'>I came across a requirement where we needed to create types dynamically based on XML Configuration files, so that in the furture new types are required we dont need to update the application again by creating a new class.  &lt;br/&gt; The additional requirement was to populate the property names of the class based on the Cml configuration and its values using the Querystring values from the HttpWebRequest. &lt;br/&gt; I earlier thought about using &lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/en-us/library/exczf7b9.aspx&quot;&gt;Dynamic methods&lt;/a&gt; from .NET Framework 2.0, but that did not fit my purpose since I didn&#39;t need to execute methods from the dynamic type that was created. &lt;br/&gt;&lt;br/&gt; So here is the code: &lt;br/&gt; I created three helper methods &lt;br/&gt; 1. Generates the AssemblyBuilder and Module Builder objects  &lt;br/&gt; 2. Generates the TypeBuilder object.. which will be used for generating an instance of the dynamic type using Activator.CreateInstance  &lt;br/&gt;3. Create properties using Relection.Emit &lt;br/&gt; &lt;div&gt;&lt;div style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%;&quot;&gt; &lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; DynamicType&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   3:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   4:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; AssemblyBuilder asmBuilder = &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   5:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; ModuleBuilder modBuilder = &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   6:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; GenerateAssemblyAndModule()&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   8:&lt;/span&gt;         &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; (asmBuilder == &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   9:&lt;/span&gt;         {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  10:&lt;/span&gt;             AssemblyName assemblyName = &lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; AssemblyName();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  11:&lt;/span&gt;             assemblyName.Name = &lt;span style=&quot;color: #006080;&quot;&gt;&quot;DWBeacons&quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  12:&lt;/span&gt;             AppDomain thisDomain = Thread.GetDomain();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  13:&lt;/span&gt;             asmBuilder = thisDomain.DefineDynamicAssembly(&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  14:&lt;/span&gt;                          assemblyName, AssemblyBuilderAccess.Run);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  15:&lt;/span&gt;             modBuilder = asmBuilder.DefineDynamicModule(&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  16:&lt;/span&gt;                          asmBuilder.GetName().Name, &lt;span style=&quot;color: #0000ff;&quot;&gt;false&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  17:&lt;/span&gt;         }&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  18:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  19:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  20:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; TypeBuilder CreateType(ModuleBuilder modBuilder, &lt;span style=&quot;color: #0000ff;&quot;&gt;string&lt;/span&gt; typeName)&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  21:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  22:&lt;/span&gt;         TypeBuilder typeBuilder = modBuilder.DefineType(typeName,&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  23:&lt;/span&gt;                     TypeAttributes.Public |&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  24:&lt;/span&gt;                     TypeAttributes.Class |&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  25:&lt;/span&gt;                     TypeAttributes.AutoClass |&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  26:&lt;/span&gt;                     TypeAttributes.AnsiClass |&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  27:&lt;/span&gt;                     TypeAttributes.BeforeFieldInit |&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  28:&lt;/span&gt;                     TypeAttributes.AutoLayout,&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  29:&lt;/span&gt;                     &lt;span style=&quot;color: #0000ff;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #0000ff;&quot;&gt;object&lt;/span&gt;));&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  30:&lt;/span&gt;         &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; typeBuilder;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  31:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  32:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  33:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  34:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; CreateProperty(TypeBuilder t, &lt;span style=&quot;color: #0000ff;&quot;&gt;string&lt;/span&gt; name, Type typ)&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  35:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  36:&lt;/span&gt;         &lt;span style=&quot;color: #0000ff;&quot;&gt;string&lt;/span&gt; field = &lt;span style=&quot;color: #006080;&quot;&gt;&quot;_&quot;&lt;/span&gt; + name.ToLower();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  37:&lt;/span&gt;         FieldBuilder fieldBldr = t.DefineField(field, typ, FieldAttributes.Private);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  38:&lt;/span&gt;         PropertyBuilder propBldr = t.DefineProperty(name, PropertyAttributes.HasDefault, typ, &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  39:&lt;/span&gt;         MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  40:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  41:&lt;/span&gt;         MethodBuilder getPropBldr = t.DefineMethod(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;get_&quot;&lt;/span&gt; + name, getSetAttr, typ, Type.EmptyTypes);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  42:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  43:&lt;/span&gt;         ILGenerator getIL = getPropBldr.GetILGenerator();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  44:&lt;/span&gt;         getIL.Emit(OpCodes.Ldarg_0);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  45:&lt;/span&gt;         getIL.Emit(OpCodes.Ldfld, fieldBldr);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  46:&lt;/span&gt;         getIL.Emit(OpCodes.Ret);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  47:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  48:&lt;/span&gt;         MethodBuilder setPropBldr = t.DefineMethod(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;set_&quot;&lt;/span&gt; + name, getSetAttr, &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; Type[] { typ });&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  49:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  50:&lt;/span&gt;         ILGenerator setIL = setPropBldr.GetILGenerator();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  51:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  52:&lt;/span&gt;         setIL.Emit(OpCodes.Ldarg_0);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  53:&lt;/span&gt;         setIL.Emit(OpCodes.Ldarg_1);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  54:&lt;/span&gt;         setIL.Emit(OpCodes.Stfld, fieldBldr);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  55:&lt;/span&gt;         setIL.Emit(OpCodes.Ret);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  56:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  57:&lt;/span&gt;         propBldr.SetGetMethod(getPropBldr);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  58:&lt;/span&gt;         propBldr.SetSetMethod(setPropBldr);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  59:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  60:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  61:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  62:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Then to use these helper methods from the Main program I used the following:&lt;br /&gt;&lt;div&gt;&lt;div style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%;&quot;&gt;&lt;br /&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; (DynamicType.asmBuilder == &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   2:&lt;/span&gt;     DynamicType.GenerateAssemblyAndModule();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   3:&lt;/span&gt; finalType = DynamicType.modBuilder.GetType(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;Beacon11&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   4:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   5:&lt;/span&gt; TypeBuilder tb = DynamicType.CreateType(DynamicType.modBuilder, typeName);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   6:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   7:&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;foreach&lt;/span&gt; (XElement e &lt;span style=&quot;color: #0000ff;&quot;&gt;in&lt;/span&gt; beaconNode.Descendants())&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   8:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;   9:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;string&lt;/span&gt; pname = e.Attribute(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;qs&quot;&lt;/span&gt;).Value;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  10:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;string&lt;/span&gt; ptype = e.Attribute(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;type&quot;&lt;/span&gt;).Value;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  11:&lt;/span&gt;     DynamicType.CreateProperty(tb, pname, Type.GetType(ptype));&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  13:&lt;/span&gt; finalType = tb.CreateType();&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  14:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  15:&lt;/span&gt; Object obj = Activator.CreateInstance(finalType);&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  16:&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;// this sets the properties of the just instantiated class&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  17:&lt;/span&gt; finalType.InvokeMember(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;bv&quot;&lt;/span&gt;, BindingFlags.SetProperty, &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;, data, &lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;object&lt;/span&gt;[] { 1.0 });&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  18:&lt;/span&gt; finalType.InvokeMember(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tp&quot;&lt;/span&gt;, BindingFlags.SetProperty, &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;, data, &lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;object&lt;/span&gt;[] { 2.0 });&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  19:&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;//this sets the properties of the type by using values from the querystring&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  20:&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;foreach&lt;/span&gt; (XElement e &lt;span style=&quot;color: #0000ff;&quot;&gt;in&lt;/span&gt; beaconNode.Descendants())&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  21:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  22:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;string&lt;/span&gt; pname = e.Attribute(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;qs&quot;&lt;/span&gt;).Value;&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  23:&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;object&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;value&lt;/span&gt; = context.Request.QueryString[pname];&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  24:&lt;/span&gt;     finalType.InvokeMember(pname, BindingFlags.SetProperty, &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;, data, &lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;object&lt;/span&gt;[] { &lt;span style=&quot;color: #0000ff;&quot;&gt;value&lt;/span&gt; });&lt;/pre&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;&lt;span style=&quot;color: #606060;&quot;&gt;  25:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;For more information visit : &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.reflection.emit.propertybuilder.aspx&quot; target=&quot;_blank&quot;&gt;msdn - PropertyBuilder&lt;/a&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5511951365340036793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/5511951365340036793' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5511951365340036793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5511951365340036793'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/12/dynamically-creating-types-using.html' title='Dynamically creating types using reflection and setting properties using Reflection.Emit.'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3924405795540805746</id><published>2008-11-18T13:32:00.001-05:00</published><updated>2008-11-18T13:34:57.372-05:00</updated><title type='text'>Schedule a task using C# code</title><content type='html'>I needed to schedule a task to run every day at 9:00 p.m. in the night. I had an addition al requirement that the task be scheduled only if the FileSystemwatcher alerts us of new files being available for processing.&lt;br/&gt;&lt;br/&gt;  Thus the files could be recieved anytime during the day, but despite that the task should be schduled to run exactly at 9:00 p.m. in the night.&lt;br/&gt;&lt;br/&gt;  So I used the following code to schedule a task(using System.Threading.Timer and TimeSpan classes) &lt;br/&gt;&lt;br/&gt;  &lt;div&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;DateTime d = DateTime.Now;&lt;br/&gt;&lt;br /&gt;timer = &lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; Timer(&lt;span style=&quot;color: #0000ff;&quot;&gt;new&lt;/span&gt; TimerCallback(Update), &lt;span style=&quot;color: #0000ff;&quot;&gt;null&lt;/span&gt;, &lt;br /&gt;TimeSpan.FromMinutes(21 * 60 - (d.Hour * 60 + d.Minute)), &lt;br /&gt;TimeSpan.FromMilliseconds(-1));&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Note I used TimeSpan.FromMillisecnods(-1) to disable periodic signalling  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3924405795540805746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/3924405795540805746' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3924405795540805746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3924405795540805746'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/11/schedule-task-using-c-code.html' title='Schedule a task using C# code'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8483877860625290346</id><published>2008-11-13T14:40:00.001-05:00</published><updated>2008-11-13T14:40:13.760-05:00</updated><title type='text'>Compare 2 SQL queries for equality</title><content type='html'>&lt;div&gt;&lt;pre style=&quot;background-color: #f4f4f4; font-family: Consolas, &#39;Courier New&#39;, Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;&quot;&gt;DECLARE @check1 bigint&lt;br /&gt;DECLARE @check2 bigint&lt;br /&gt;&lt;br /&gt;Select @check1 = CHECKSUM_AGG(CHECKSUM(*))&lt;br /&gt;FROM&lt;br /&gt;(&lt;br /&gt;    SELECT *&lt;br /&gt;    FROM dbo.Orders (nolock)&lt;br /&gt;)&lt;br /&gt;AS Source&lt;br /&gt;&lt;br /&gt;Select @check2 = CHECKSUM_AGG(CHECKSUM(*))&lt;br /&gt;FROM&lt;br /&gt;(&lt;br /&gt;    SELECT *&lt;br /&gt;    FROM dbo.Orders (nolock)&lt;br /&gt;    WHERE IsSuccessful = 1&lt;br /&gt;)&lt;br /&gt;As Comparison&lt;br /&gt;&lt;br /&gt;IF @check1 = @check2&lt;br /&gt;    PRINT &lt;span style=&quot;color: #006080;&quot;&gt;&#39;Queries are Equal&#39;&lt;/span&gt;&lt;br /&gt;ELSE&lt;br /&gt;    PRINT &lt;span style=&quot;color: #006080;&quot;&gt;&#39;Queries are NOT Equal&#39;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;If order of rows is different it will not effect the result &lt;br /&gt;It does not do execution plan comparisons, simply checks if the rows returned by the two queries are the same or not&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://blog.troyd.net/How+To+Compare++Test+The+Equality+Of+Two+Queries+In+SQL+Server+With+SQL.aspx&quot; target=&quot;_blank&quot;&gt;More info&lt;/a&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8483877860625290346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/8483877860625290346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8483877860625290346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8483877860625290346'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/11/compare-2-sql-queries-for-equality.html' title='Compare 2 SQL queries for equality'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-677665481818187195</id><published>2008-11-12T16:56:00.001-05:00</published><updated>2008-11-12T16:58:45.589-05:00</updated><title type='text'>Converting SQL2005 DBTimeStamp to Long for Comparison (Convert from Hex to long and decimal to Hex)</title><content type='html'>If you need to Convert SQL 2005 DB TimeStamp values to Long then follow these steps: &lt;br/&gt; 1. Retrieve the DB TimeStamp value in a Byte Array (8 bytes long). &lt;br/&gt; 2. Convert the byte array into a Hexadecimal string &lt;br/&gt; 3. Convert the hexadecimal string to a long &lt;br/&gt;  &lt;div&gt;   &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;long&lt;/span&gt; BytesToLong(&lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt;[] bytes)&lt;br /&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; ts = &lt;span style=&quot;color: #0000ff&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt; b &lt;span style=&quot;color: #0000ff&quot;&gt;in&lt;/span&gt; bytes)&lt;br /&gt;        ts += b.ToString(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;X&amp;quot;&lt;/span&gt;).PadLeft(2,Convert.ToChar(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;));&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; Convert.ToInt64(ts, 16);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;There is another method to convert the DBTimeStamp to Long, but I dont prefer this method since it can return negative values. The method is:&lt;br/&gt;&lt;br /&gt;1. Retrieve the DB TimeStamp value in a Byte Array (8 bytes long).&lt;br /&gt;2. Use BitConverter class to convert the byte array into long &lt;br /&gt;&lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;long result = BitConverter.ToInt64(dbTimestamp, 0); &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Inorder to remedy this use the following to generate the same long value as in step 1:&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;long&lt;/span&gt; FromDbTimestamp(&lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt;[] dbTimestamp)&lt;br /&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;long&lt;/span&gt; result = 0;&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (dbTimestamp != &lt;span style=&quot;color: #0000ff&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        Array.Reverse(dbTimestamp);&lt;br /&gt;        result = BitConverter.ToInt64(dbTimestamp, 0);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; result;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;Finally to convert a long into the correct DBTimeStamp use this: &lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt;[] ToDbTimestamp(&lt;span style=&quot;color: #0000ff&quot;&gt;long&lt;/span&gt; timestamp)&lt;br /&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt;[] result = BitConverter.GetBytes(timestamp);&lt;br /&gt;    Array.Reverse(result);&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; result;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/677665481818187195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/677665481818187195' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/677665481818187195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/677665481818187195'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/11/converting-sql2005-dbtimestamp-to-long.html' title='Converting SQL2005 DBTimeStamp to Long for Comparison (Convert from Hex to long and decimal to Hex)'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5250687481671371701</id><published>2008-10-13T13:23:00.001-04:00</published><updated>2008-10-13T18:12:08.292-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>Passing state to threads via anonymous calls</title><content type='html'>&lt;p&gt;We already know that we can pass state into to Threads in 2 ways:&lt;/p&gt;  &lt;p&gt;1. using ParameterizedThreadStart delegate&lt;/p&gt; 2.using global variables(reference or value types) accessible to the main thread as well the instantiated thread. This is also the  way to share data amonst multiple threads. Infact the most common way to share data between threads is using static variables where application wide scope is desired. &lt;p&gt;3.using Thread.QueueUserWorkItem ... This differs from Parameterized ThreadStart delegate since it uses threads from a preconfigured ThreadPool instead of manually creating threads &lt;/p&gt;  There is another cool method to pass information to threads is via anonymous methods. For e.g.   &lt;div&gt;   &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; Main&lt;br /&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; mainMessage = &lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Hello from Main !!!&amp;quot;&lt;/span&gt;;&lt;br /&gt;    Thread t = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; Thread(&lt;span style=&quot;color: #0000ff&quot;&gt;delegate&lt;/span&gt;() { Print(mainMessage);});&lt;br /&gt;    t.Start();&lt;br /&gt;}&lt;br /&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; Print(&lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; message)&lt;br /&gt;{&lt;br /&gt;    Console.Writeline(message);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;Advantage of using this technique is that, it provides strongly typed access to the parameters passed to the thread. The Target Method can accept &lt;strong&gt;&lt;u&gt;any&lt;/u&gt;&lt;/strong&gt; number of arguments, and no casting is required (unlike Parameterized Start where the passed state is an “object”) . The flip side, though, is that you must keep outer-variable semantics in mind &lt;br /&gt;&lt;br /&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5250687481671371701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/5250687481671371701' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5250687481671371701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5250687481671371701'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/10/passing-state-to-threads-via-anonymous.html' title='Passing state to threads via anonymous calls'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4916472706414653446</id><published>2008-09-26T20:57:00.004-04:00</published><updated>2008-10-13T18:12:08.292-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>Method Hiding... Polymorphism in C#</title><content type='html'>&lt;h4&gt;In the following code:&lt;/h4&gt;  &lt;div&gt;   &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;interface&lt;/span&gt; IBand&lt;br /&gt; {&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; ID {get;set;}&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; Name {get;set;}&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; GetStatus();&lt;br /&gt; }&lt;br /&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;class&lt;/span&gt; Band : IBand&lt;br /&gt; {&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; ID { get; set; }&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; Name { get; set; }&lt;br /&gt;&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; Band()&lt;br /&gt;     {&lt;br /&gt;         GetStatus();&lt;br /&gt;     }&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; GetStatus()&lt;br /&gt;     {&lt;br /&gt;         ID = 555;&lt;br /&gt;         Name = &lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Ring&amp;quot;&lt;/span&gt;;&lt;br /&gt;         Console.WriteLine(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Base Class Called&amp;quot;&lt;/span&gt;);&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;class&lt;/span&gt; ABand : Band, IBand&lt;br /&gt; {&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; Update { get; set; }&lt;br /&gt;&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; ABand() : &lt;span style=&quot;color: #0000ff&quot;&gt;base&lt;/span&gt;() {}&lt;br /&gt;&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; GetStatus()&lt;br /&gt;     {&lt;br /&gt;         ID = 655;&lt;br /&gt;         Name = &lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;TEsst&amp;quot;&lt;/span&gt;;&lt;br /&gt;         Update = &lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;ddd&amp;quot;&lt;/span&gt;;&lt;br /&gt;         Console.WriteLine(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Derived class Called&amp;quot;&lt;/span&gt;);&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;class&lt;/span&gt; Program&lt;br /&gt; {&lt;br /&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; Main(&lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt;[] args)&lt;br /&gt;     {&lt;br /&gt;         IBand band = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; ABand();&lt;br /&gt;         band.GetStatus();&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;We have 2 classes, Band and ABand which implement the IBand interface explicitly.&lt;br /&gt;&lt;br /&gt;Now the call to band.GetStatus in Main will display &amp;quot;Derived class called&amp;quot;. This will only happen if the Derived class (ABand) also implements the interface IBand explicitly (not in the literal sense in that it does not implement the methods using the IBand.GetStatus syntax) &lt;br /&gt;&lt;br /&gt;If the ABand class does not implement the IBand interface explicitly (but implicitly since it inherits from Band which implements IBand) then the above code will output &amp;quot;Base class called&amp;quot; &lt;br /&gt;&lt;br /&gt;However note one thing, that when the CTor for ABand is invoked it will invoke the ctor Band class and which will call GetStatus() method from within Band class hence this will output &amp;quot;Base class called&amp;quot; even though the ABand class has implemented the IBand interface explicilty.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4916472706414653446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/4916472706414653446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4916472706414653446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4916472706414653446'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/09/method-hiding-polymorphism-in-c.html' title='Method Hiding... Polymorphism in C#'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3109305841424623515</id><published>2008-09-09T20:23:00.002-04:00</published><updated>2008-09-09T20:42:32.169-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>Linq To XML : Check for existence of an element</title><content type='html'>&lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;var bookQuery = &lt;br /&gt;from book &lt;span style=&quot;color: #0000ff&quot;&gt;in&lt;/span&gt; bookXml.Descendants(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Item&amp;quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;let attributes = book.Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;ItemAttributes&amp;quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;let price = Decimal.Parse((&lt;br /&gt;  book.Elements(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;OfferSummary&amp;quot;&lt;/span&gt;).Any() &lt;br /&gt;  &amp;amp;&amp;amp; book.Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;OfferSummary&amp;quot;&lt;/span&gt;).Elements(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;LowestNewPrice&amp;quot;&lt;/span&gt;).Any()&lt;br /&gt;  ? book.Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;OfferSummary&amp;quot;&lt;/span&gt;).Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;LowestNewPrice&amp;quot;&lt;/span&gt;).Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Amount&amp;quot;&lt;/span&gt;).Value&lt;br /&gt;  : (attributes.Elements(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;ListPrice&amp;quot;&lt;/span&gt;).Any()&lt;br /&gt;      ? attributes.Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;ListPrice&amp;quot;&lt;/span&gt;).Element(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Amount&amp;quot;&lt;/span&gt;).Value &lt;br /&gt;      : &lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;))) / 100&lt;br /&gt;&lt;br /&gt;select &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; {Price = price};&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The trick is to use the Elements(“node”) instead of Element(“node”) and then use the Any() function which will return true if an element of that name exists.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Some other LINQ tips:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Some of the extensions that one can use are Intersect,Union &amp;amp;&amp;amp; Except &lt;br /&gt;  &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;var list1 = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; List&amp;lt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt;&amp;gt; { 2, 4, 9, 11, 3, 6 };&lt;br /&gt;var list2 = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; List&amp;lt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt;&amp;gt; { 3, 8, 4, 30, 9, 16 };&lt;br /&gt;var newlist = list1.Intersect(list2);&lt;/pre&gt;&lt;br /&gt;This returns : 3,4,9&lt;br /&gt;newlist = list1.Union(list2);&lt;br /&gt;this returns : 2,3,4,6,8,9,11,16,30. finally &lt;br /&gt;newlist = list1.Except(list2);&lt;br /&gt;returns : 2,11,6</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3109305841424623515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/3109305841424623515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3109305841424623515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3109305841424623515'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/09/linq-to-xml-check-for-existence-of.html' title='Linq To XML : Check for existence of an element'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8054519056156161156</id><published>2008-08-26T14:57:00.001-04:00</published><updated>2008-10-13T18:12:17.077-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>Convert Array of Ints into bytes</title><content type='html'>&lt;p&gt;Here is the code to convert array of Ints to bytes:&lt;/p&gt;  &lt;div&gt;   &lt;pre style=&quot;padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt;[] source = ids.ToArray();&lt;br /&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; length = source.Length * 4;&lt;br /&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt;[] dest = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;byte&lt;/span&gt;[length];&lt;br /&gt;System.Buffer.BlockCopy(source, 0, dest, 0, dest.Length);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8054519056156161156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/8054519056156161156' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8054519056156161156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8054519056156161156'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/08/convert-array-of-ints-into-bytes.html' title='Convert Array of Ints into bytes'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3555409414658348433</id><published>2008-07-25T12:44:00.001-04:00</published><updated>2008-10-13T18:12:25.244-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aspnet20"/><title type='text'>Alternating styles in ListView- without AlternatingItemTemplate</title><content type='html'>&lt;p&gt;From within any template, you have access to the current index of the row within the whole data set, using &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewdataitem.dataitemindex.aspx&quot;&gt;Container.DataItemIndex&lt;/a&gt;, and within the currently displayed items, using &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewdataitem.displayindex.aspx&quot;&gt;Container.DisplayIndex&lt;/a&gt;. This gives us an easy way to alternate styles:&lt;/p&gt;  &lt;pre&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;  &amp;lt;li class=&amp;quot;&amp;lt;%# Container.DisplayIndex % 2 == 0 ? &amp;quot;even&amp;quot; : &amp;quot;odd&amp;quot; %&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;%# Eval(&amp;quot;Name&amp;quot;) %&amp;gt;&lt;br /&gt;  &amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Just define the even and odd classes in your stylesheet and you&#39;re pretty much done.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3555409414658348433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/3555409414658348433' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3555409414658348433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3555409414658348433'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/07/alternating-styles-in-listview-without.html' title='Alternating styles in ListView- without AlternatingItemTemplate'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6547370845336329128</id><published>2008-07-24T22:53:00.001-04:00</published><updated>2008-07-24T23:01:00.687-04:00</updated><title type='text'>Batch Inserts to SQL Server- Stored procedure method</title><content type='html'>&lt;p&gt;To do batch Updates to SQL server &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create DataTable or DataSet and populate it with required rows &lt;/li&gt;    &lt;li&gt;Next Create a SqlCommand and SqlDataAdapter using that SqlCommand &lt;/li&gt;    &lt;li&gt;Remember to set the UpdateRowSource property on the Command the the appropriate value&lt;/li&gt;    &lt;li&gt;Set the UpdateBatchSize Property on the SqlDataAdapter &lt;/li&gt;    &lt;li&gt;then call SqlDataAdapter.Update(dt) to push the updates to SQL server &lt;/li&gt; &lt;/ul&gt;  &lt;div&gt;   &lt;div&gt;     &lt;pre style=&quot;padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none&quot;&gt;DataTable dt = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; DataTable();&lt;br /&gt;dt.Columns.Add(&lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; DataColumn(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;asin&amp;quot;&lt;/span&gt;));&lt;br /&gt;dt.Columns.Add(&lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; DataColumn(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;trackasin&amp;quot;&lt;/span&gt;));&lt;br /&gt;dt.Columns.Add(&lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; DataColumn(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;isrc&amp;quot;&lt;/span&gt;));&lt;br /&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt;(&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i =0; i &amp;lt; 2000;i++)&lt;br /&gt;{&lt;br /&gt;    DataRow dr = dt.NewRow();&lt;br /&gt;    dr[&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;asin&amp;quot;&lt;/span&gt;] = asin;&lt;br /&gt;    dr[&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;trackasin&amp;quot;&lt;/span&gt;] = trackasin;&lt;br /&gt;    dr[&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;isrc&amp;quot;&lt;/span&gt;] = isrc;&lt;br /&gt;    &lt;span style=&quot;color: #008000&quot;&gt;//dr.RowState = DataRowState.Added;&lt;/span&gt;&lt;br /&gt;    dt.Rows.Add(dr);&lt;br /&gt;}&lt;br /&gt;------------------------------------------------&lt;br /&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;using&lt;/span&gt; (SqlConnection connection = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; SqlConnection(ConfigurationManager.ConnectionStrings[&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;MySpaceMusic&amp;quot;&lt;/span&gt;].ConnectionString))&lt;br /&gt;{&lt;br /&gt;    SqlCommand command = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; SqlCommand(INSERT_TRACK, connection);&lt;br /&gt;    command.CommandType = CommandType.StoredProcedure;&lt;br /&gt;    command.UpdatedRowSource = UpdateRowSource.None;&lt;br /&gt;    command.CommandTimeout = commandTimeout;&lt;br /&gt;&lt;br /&gt;    command.Parameters.Add(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;@asin&amp;quot;&lt;/span&gt;, SqlDbType.VarChar, 255, dt.Columns[0].ColumnName);&lt;br /&gt;    command.Parameters.Add(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;@trackAsin&amp;quot;&lt;/span&gt;, SqlDbType.VarChar, 255, dt.Columns[1].ColumnName);&lt;br /&gt;    command.Parameters.Add(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;@isrc&amp;quot;&lt;/span&gt;, SqlDbType.VarChar, 600, dt.Columns[2].ColumnName);&lt;br /&gt;&lt;br /&gt;    SqlDataAdapter adpt = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; SqlDataAdapter();&lt;br /&gt;&lt;br /&gt;    adpt.InsertCommand = command;&lt;br /&gt;    adpt.UpdateBatchSize = batchSize;&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        connection.Open();&lt;br /&gt;        &lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; recordsInserted = adpt.Update(dt);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;finally&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        adpt.Dispose();&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6547370845336329128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/6547370845336329128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6547370845336329128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6547370845336329128'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/07/batch-inserts-to-sql-server-stored.html' title='Batch Inserts to SQL Server- Stored procedure method'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1798885924883133403</id><published>2008-07-03T01:42:00.002-04:00</published><updated>2008-07-03T01:44:53.424-04:00</updated><title type='text'>क्यूट सोंग .. नानी तेरी मोरनी को मोर ले गए</title><content type='html'>Naani Teri Morni Ko Mor Le Gaye &lt;br /&gt;Baaki Jo Bacha Tha Kaale Chor Le Gaye&lt;br /&gt;&lt;br /&gt; Khaake Peeke Mote Hoke, &lt;br /&gt;Chor Baithe Rail Mein &lt;br /&gt;Choron Vaala Dibba Kat Ke, Pahuncha Seedhe Jail Mein &lt;br /&gt;&lt;br /&gt;Naani Teri Morni Ko... &lt;br /&gt;&lt;br /&gt;Un Choron Ki Khoob Khabar Li, &lt;br /&gt;Mote Thaanedaar Ne &lt;br /&gt;Moron Ko Bhi Khoob Nachaaya, &lt;br /&gt;Jungal Ki Sarkaar Ne &lt;br /&gt;&lt;br /&gt;Naani Teri Morni Ko... &lt;br /&gt;Achhi Naani Pyaari Naani, &lt;br /&gt;Roosa-Roosi Chhod De Jaldi Se Ek Paisa De De, &lt;br /&gt;Tu Kanjoosi chod de...&lt;br /&gt;&lt;br /&gt;Nani teri morni ko chor le gaye&lt;br /&gt;baaki jo bacha tha kaale chor le gaye</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1798885924883133403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/1798885924883133403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1798885924883133403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1798885924883133403'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/07/blog-post.html' title='क्यूट सोंग .. नानी तेरी मोरनी को मोर ले गए'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4999513503733434952</id><published>2008-05-06T01:56:00.001-04:00</published><updated>2008-05-06T01:56:54.211-04:00</updated><title type='text'>Unity Application block and Generic Singleton</title><content type='html'>&lt;p&gt;Here are some features of the Unity Application block. (Note there is overhead in using this block&amp;#8230; i.e. overhead while creating instances of objects that have dependent objects)&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/cc440954.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/cc440954.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160; Highlights of the Unity Application Block &lt;/p&gt;  &lt;p&gt;&lt;a name=&quot;sectionToggle2&quot;&gt;&lt;/a&gt;&lt;a name=&quot;intro_highlights&quot;&gt;&lt;/a&gt;The Unity Application Block includes the following features:&lt;/p&gt;  &lt;p&gt;&amp;#183; It provides a mechanism for building (or assembling) instances of objects, which may contain other dependent object instances. &lt;/p&gt;  &lt;p&gt;&amp;#183; It exposes &lt;b&gt;RegisterType&lt;/b&gt; methods that support configuring the container with type mappings and objects (&lt;b&gt;including singleton instances&lt;/b&gt;) and &lt;b&gt;Resolve&lt;/b&gt; methods that return instances of built objects that can contain any dependent objects. &lt;/p&gt;  &lt;p&gt;&amp;#183; It provides inversion of control (IoC) functionality by allowing injection of preconfigured objects into classes built by the application block. Developers can specify an interface or class type in the constructor (constructor injection) or apply to properties and methods attributes to initiate property injection and method call injection. &lt;/p&gt;  &lt;p&gt;&amp;#183; It supports a hierarchy for containers. A container may have child container(s), allowing object location queries to pass from the child out through the parent container(s). &lt;/p&gt;  &lt;p&gt;&amp;#183; &lt;b&gt;It can read configuration information from standard configuration systems, such as XML files, and use it to configure the containe&lt;/b&gt;r( The Unity Container which hold references to the objects built using Resolve method). &lt;/p&gt;  &lt;p&gt;&amp;#183; It makes no demands on the object class definition. There is no requirement to apply attributes to classes (except when using property or method call injection), and there are no limitations on the class declaration. &lt;/p&gt;  &lt;p&gt;&amp;#183; It supports custom container extensions that developers can implement; for example, methods to allow additional object construction and container features such as caching. &lt;/p&gt;  &lt;p&gt;And here is the code for the Generic Singleton:&lt;/p&gt;  &lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;/// Provides a Singleton implementation using Generics.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;Type of singleton instance&amp;lt;/typeparam&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;sealed&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Singleton&amp;lt;T&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;where&lt;/span&gt; T : &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt;()&lt;br /&gt;        {&lt;br /&gt;            Singleton() { }&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; T Instance&lt;br /&gt;            {&lt;br /&gt;                get&lt;br /&gt;                { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Nested.instance; }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;             &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Nested&lt;br /&gt;            {&lt;br /&gt;                &lt;span class=&quot;rem&quot;&gt;// Explicit static constructor to tell C# compiler&lt;/span&gt;&lt;br /&gt;                &lt;span class=&quot;rem&quot;&gt;// not to mark type as beforefieldinit&lt;/span&gt;&lt;br /&gt;                &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; Nested() { }&lt;br /&gt;                &lt;span class=&quot;kwrd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;readonly&lt;/span&gt; T instance = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; T();&lt;br /&gt;            }&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The code for returning the instance then becomes:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;csharpcode&quot;&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; BlogSettings Instance&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Utils.Singleton&amp;lt;BlogSettings&amp;gt;.Instance;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;You have to also change the constructor for BlogSettings to public to allow this this to work&lt;/pre&gt;&lt;br /&gt;&lt;style type=&quot;text/css&quot;&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, &quot;Courier New&quot;, 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;/style&gt;&lt;style type=&quot;text/css&quot;&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, &quot;Courier New&quot;, 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;/style&gt;  </content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4999513503733434952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4971377397859266634/4999513503733434952' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4999513503733434952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4999513503733434952'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/05/unity-application-block-and-generic.html' title='Unity Application block and Generic Singleton'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>