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

<channel>
	<title>I&#039;m Bao Nguyen ( Nguyễn Đức Phúc Bảo ). Welcome</title>
	<atom:link href="http://baondp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://baondp.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 08 Apr 2011 03:11:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='baondp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/44201e903a442b77082605cee0124aa2?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>I&#039;m Bao Nguyen ( Nguyễn Đức Phúc Bảo ). Welcome</title>
		<link>http://baondp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://baondp.wordpress.com/osd.xml" title="I&#039;m Bao Nguyen ( Nguyễn Đức Phúc Bảo ). Welcome" />
	<atom:link rel='hub' href='http://baondp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Visual Studio xml formatting error &#8220;an error occurred loading this property page&#8221;</title>
		<link>http://baondp.wordpress.com/2009/12/23/visual-studio-xml-formatting-error-an-error-occurred-loading-this-property-page/</link>
		<comments>http://baondp.wordpress.com/2009/12/23/visual-studio-xml-formatting-error-an-error-occurred-loading-this-property-page/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 08:18:27 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=103</guid>
		<description><![CDATA[I using VS2008 and got error xml. After that I can’t read web.config (so bad) and go to Option &#8211;&#62; Text Editor &#8211;&#62; XML &#8211;&#62; Formatting got a bad message &#8220;an error occurred loading this property page&#8220; And Google’s time&#8230;. i searched solution for that. Search with keyword &#8220;vs 2008 option xml formatting error&#8220; To [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=103&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I using VS2008 and got error xml. After that I can’t read web.config (so bad) and go to Option &#8211;&gt; Text Editor &#8211;&gt; XML &#8211;&gt; Formatting got a bad message &#8220;<span style="color:#ff0000;">an error occurred loading this property page</span>&#8220;</p>
<p>And Google’s time&#8230;. i searched solution for that. Search with keyword &#8220;<span style="color:#0000ff;">vs 2008 option xml formatting error</span>&#8220;</p>
<p>To fix this issue need to do:</p>
<p>Step 1: Open cmd “Run &#8211;&gt; cmd”</p>
<p>Step 2: Go to the path:</p>
<p>-          VS2005: “C:\Program Files\Microsoft Visual Studio 8\VC\”</p>
<p>-          VS2008: “C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\”</p>
<p>Step 3: Typing magic command:</p>
<p><span style="color:#993300;"><strong>devenv /setup</strong></span></p>
<p>Step 4: Wait…wait…it take one or two minutes</p>
<p>Step 5: Open VS again and look the nice result.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=103&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/12/23/visual-studio-xml-formatting-error-an-error-occurred-loading-this-property-page/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>How change the view location in MVC? / How to use ViewEngine in MVC?</title>
		<link>http://baondp.wordpress.com/2009/11/30/how-change-the-view-location-in-mvc-how-to-use-viewengine-in-mvc/</link>
		<comments>http://baondp.wordpress.com/2009/11/30/how-change-the-view-location-in-mvc-how-to-use-viewengine-in-mvc/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 06:20:17 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[ASP.Net MVC]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=95</guid>
		<description><![CDATA[In my personal project, i got a needs building various layout for each flow .I researched on google and got a solution. That is customize ViewEngine in MVC. Default ViewLocation is: ~/Views/&#60;controller&#62;/&#60;viewname&#62;.aspx ~/Views/&#60;controller&#62;/&#60;viewname&#62;.ascx For customize default view engine , created a class inherit WebFormViewEngine. For example i created MyViewEngine public class MyViewEngine : WebFormViewEngine { [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=95&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my personal project, i got a needs building various layout for each flow .I researched on google and got a solution.</p>
<p>That is customize ViewEngine in MVC. <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Default ViewLocation is:</p>
<blockquote><p>~/Views/&lt;controller&gt;/&lt;viewname&gt;.aspx</p>
<p>~/Views/&lt;controller&gt;/&lt;viewname&gt;.ascx</p></blockquote>
<p>For customize default view engine , created a class inherit <em>WebFormViewEngine.</em> For example i created <em>MyViewEngine</em></p>
<pre>
public class MyViewEngine : WebFormViewEngine
{

    public MyViewEngine()
    {
        base.MasterLocationFormats = new string[] {
            "~/Themes/{2}/Views/{1}/{0}.master",
            "~/Themes/{2}/Views/Shared/{0}.master"
        };
        base.ViewLocationFormats = new string[] {
            "~/Themes/{2}/Views/{1}/{0}.aspx",
            "~/Themes/{2}/Views/{1}/{0}.ascx",
            "~/Themes/{2}/Views/Shared/{0}.aspx",
            "~/Themes/{2}/Views/Shared/{0}.ascx"
        };
        base.PartialViewLocationFormats = ViewLocationFormats ;
    }

public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {
        //Customize any path for return ViewEngineResult
    }
}
</pre>
<p>Add customized viewengine to ViewEngines:</p>
<pre>
protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);

    // Replace the Default WebFormViewEngine with our custom WebFormThemeViewEngine
    System.Web.Mvc.ViewEngines.Engines.Clear();
    System.Web.Mvc.ViewEngines.Engines.Add(new MyViewEngine());
}
</pre>
<p>I will post the sample code soon.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=95&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/11/30/how-change-the-view-location-in-mvc-how-to-use-viewengine-in-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>Excel : Search And Replace by VBscript.</title>
		<link>http://baondp.wordpress.com/2009/05/28/excel-search-and-replace-by-vbscript/</link>
		<comments>http://baondp.wordpress.com/2009/05/28/excel-search-and-replace-by-vbscript/#comments</comments>
		<pubDate>Thu, 28 May 2009 03:51:30 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=90</guid>
		<description><![CDATA[Sub Replace() Application.ScreenUpdating = False Application.Calculation = xlManual Dim cell As Range For Each cell In Intersect(Selection, _ ActiveSheet.UsedRange) If IsNumeric(cell) = False And Trim(cell) = "." And cell.Row &#62; 1 Then cell.Value = "" End If Next cell Application.Calculation = xlAutomatic 'xlCalculationAutomatic Application.ScreenUpdating = False End Sub Adding the Macro 1. Copy the macro [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=90&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre>Sub Replace()

Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim cell As Range
For Each cell In Intersect(Selection, _
ActiveSheet.UsedRange)
If IsNumeric(cell) = False And Trim(cell) = "." And cell.Row &gt; 1 Then
cell.Value = ""
End If
Next cell
Application.Calculation = xlAutomatic 'xlCalculationAutomatic
Application.ScreenUpdating = False

End Sub</pre>
<p><span style="font-family:Arial;color:#000000;"><strong>Adding the Macro</strong><br />
1. <strong>Copy</strong> the macro above pressing the keys <strong>CTRL+C</strong><br />
2. Open your workbook<br />
3. Press the keys <strong>ALT+F11</strong> to open the Visual Basic Editor<br />
4. Press the keys <strong>ALT+I</strong> to activate the <strong>Insert menu</strong><br />
5. <strong>Press M</strong> to insert a <strong>Standard Module</strong><br />
6. <strong>Paste</strong> the code by pressing the keys <strong>CTRL+V</strong><br />
<span style="color:red;">7. Make any custom changes to the macro if needed at this time</span><br />
8. <strong>Save the Macro</strong> by pressing the keys <strong>CTRL+S</strong><br />
9. Press the keys <strong>ALT+Q</strong> to exit the Editor, and return to Excel.</span></p>
<p><strong>To Run the Macro&#8230;</strong><br />
To run the macro from Excel, open the workbook, and press <strong>ALT+F8</strong> to display the <strong>Run Macro Dialog</strong>. Double Click the macro&#8217;s name to <strong>Run</strong> it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=90&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/05/28/excel-search-and-replace-by-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>PostgreSQL Tips: Get tablenames and column in database</title>
		<link>http://baondp.wordpress.com/2009/04/08/postgressql-tips-get-tablenames-and-column-in-database/</link>
		<comments>http://baondp.wordpress.com/2009/04/08/postgressql-tips-get-tablenames-and-column-in-database/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 08:29:47 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=86</guid>
		<description><![CDATA[I have requirement need script. I did it and i share it, hope it&#8217;ll useful for someone. SELECT t.tablename, a.attname AS "Column" --,pg_catalog.format_type (a.atttypid, a.atttypmod) AS "Datatype" FROM pg_tables t, pg_catalog.pg_attribute a WHERE a.attnum &#62; 0 AND NOT a.attisdropped AND a.attrelid = ( SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON   n.oid = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=86&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have requirement need script. I did it and i share it, hope it&#8217;ll useful for someone.</p>
<pre>SELECT
t.tablename,
a.attname AS "Column"
--,pg_catalog.format_type (a.atttypid, a.atttypmod) AS "Datatype"
FROM
pg_tables t,
pg_catalog.pg_attribute a
WHERE
a.attnum &gt; 0
AND NOT a.attisdropped
AND a.attrelid = (
SELECT
c.oid
FROM
pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n
ON   n.oid = c.relnamespace
WHERE
c.relname = t.tablename
AND pg_catalog.pg_table_is_visible (c.oid)
)
AND t.tablename NOT LIKE 'pg%'
AND t.tablename NOT LIKE 'sql%'</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=86&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/08/postgressql-tips-get-tablenames-and-column-in-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate Tips: Updating objects</title>
		<link>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-updating-objects/</link>
		<comments>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-updating-objects/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 11:57:33 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=84</guid>
		<description><![CDATA[1. Updating in the same ISession Transactional persistent instances (ie. objects loaded, saved, created or queried by the ISession) may be manipulated by the application and any changes to persistent state will be persisted when the ISession is flushed (discussed later in this chapter). So the most straightforward way to update the state of an object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=84&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>1. Updating in the same ISession</h3>
<p><span><em>Transactional persistent instances</em></span> (ie. objects loaded, saved, created or                 queried by the <tt>ISession</tt>) may be manipulated by the application                 and any changes to persistent state will be persisted when the <tt>ISession</tt> is <span><em>flushed</em></span> (discussed later in this chapter). So the most                 straightforward way to update the state of an object is to <tt>Load()</tt> it,                 and then manipulate it directly, while the <tt>ISession</tt> is open:</p>
<pre>DomesticCat cat = (DomesticCat) sess.Load( typeof(Cat), 69L );
cat.Name = "PK";
sess.Flush();  // changes to cat are automatically detected and persisted</pre>
<p>Sometimes this programming model is inefficient since it would require both an SQL                 <tt>SELECT</tt> (to load an object) and an SQL <tt>UPDATE</tt> (to persist its updated state) in the same session. Therefore NHibernate offers an alternate approach.</p>
<div lang="en">
<div>
<div>
<div><a class="knol-anchor-headings" name="9(2E)4(2E)2(2E)(C2)(A0)Updating_detached_objects"></a></p>
<h3>2. Updating detached objects</h3>
</div>
</div>
</div>
<p>Many applications need to retrieve an object in one transaction, send it to the UI layer for manipulation, then save the changes in a new transaction. (Applications that use this kind of approach in a high-concurrency environment usually use versioned data to ensure transaction isolation.) This approach requires a slightly different programming model to the one described in the last section. NHibernate supports this model by providing the method <tt>Session.Update()</tt>.</p>
<pre>// in the first session
Cat cat = (Cat) firstSession.Load(typeof(Cat), catId);
Cat potentialMate = new Cat();
firstSession.Save(potentialMate);

// in a higher tier of the application
cat.Mate = potentialMate;

// later, in a new session
secondSession.Update(cat);  // update cat
secondSession.Update(mate); // update mate</pre>
<p>If the <tt>Cat</tt> with identifier <tt>catId</tt> had already                 been loaded  by <tt>secondSession</tt> when the application tried to                 update it, an exception would have been thrown.</p>
<p>The application should individually <tt>Update()</tt> transient instances                 reachable from the given transient instance if and <span><em>only</em></span> if it wants                 their state also updated. (Except for lifecycle objects, discussed later.)</p>
<p>Hibernate users have requested a general purpose method that either saves a transient instance by generating a new identifier or update the persistent state associated with its current identifier. The <tt>SaveOrUpdate()</tt> method now implements this functionality.</p>
<p>NHibernate distinguishes &#8220;new&#8221; (unsaved) instances from &#8220;existing&#8221; (saved or loaded in a previous session) instances by the value of their identifier (or version, or timestamp) property. The <tt>unsaved-value</tt> attribute of the <tt>&lt;id&gt;</tt> (or <tt>&lt;version&gt;</tt>,                 or <tt>&lt;timestamp&gt;</tt>) mapping specifies which values should                 be interpreted as representing a &#8220;new&#8221; instance.</p>
<pre>&lt;id name="Id" type="Int64" column="uid" unsaved-value="0"&gt;
    &lt;generator class="hilo"/&gt;
&lt;/id&gt;</pre>
<p>The allowed values of <tt>unsaved-value</tt> are:</p>
<div>
<ul>
<li><tt>any</tt> &#8211; always save</li>
<li><tt>none</tt> &#8211; always update</li>
<li><tt>null</tt> &#8211; save when identifier is null</li>
<li>valid identifier value &#8211; save when identifier is null or the given value</li>
<li><tt>undefined</tt> &#8211; if set for <tt>version</tt> or                         <tt>timestamp</tt>, then identifier check is used</li>
</ul>
</div>
<p>If <tt>unsaved-value</tt> is not specified for a class, NHibernate will attempt to guess it by creating an instance of the class using the no-argument constructor and reading the property value from the instance.</p>
<pre>// in the first session
Cat cat = (Cat) firstSession.Load(typeof(Cat), catID);

// in a higher tier of the application
Cat mate = new Cat();
cat.Mate = mate;

// later, in a new session
secondSession.SaveOrUpdate(cat);   // update existing state (cat has a non-null id)
secondSession.SaveOrUpdate(mate);  // save the new instance (mate has a null id)</pre>
<p>The usage and semantics of <tt>SaveOrUpdate()</tt> seems to be confusing for new users. Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use <tt>Update()</tt> or                 <tt>SaveOrUpdate()</tt>. Some whole applications will never use either of                 these methods.</p>
<p>Usually <tt>Update()</tt> or <tt>SaveOrUpdate()</tt> are used in                 the following scenario:</p>
<div>
<ul>
<li>the application loads an object in the first session</li>
<li>the object is passed up to the UI tier</li>
<li>some modifications are made to the object</li>
<li>the object is passed back down to the business logic tier</li>
<li>the application persists these modifications by calling                         <tt>Update()</tt> in a second session</li>
</ul>
</div>
<p><tt>SaveOrUpdate()</tt> does the following:</p>
<div>
<ul>
<li>if the object is already persistent in this session, do nothing</li>
<li>if the object has no identifier property, <tt>Save()</tt> it</li>
<li>if the object&#8217;s identifier matches the criteria specified by                         <tt>unsaved-value</tt>, <tt>Save()</tt> it</li>
<li>if the object is versioned (<tt>version</tt> or                         <tt>timestamp</tt>), then the version will take precedence to identifier check, unless the versions <tt>unsaved-value="undefined"</tt> (default value)</li>
<li>if another object associated with the session has the same identifier, throw an exception</li>
</ul>
</div>
<p>The last case can be avoided by using <tt>SaveOrUpdateCopy(Object o)</tt>. This method copies the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. The method returns the persistent instance. If the given instance is unsaved or does not exist in the database, NHibernate will save it and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session. In most applications with detached objects, you need both methods, <tt>SaveOrUpdate()</tt> and <tt>SaveOrUpdateCopy()</tt>.</div>
<div lang="en">
<div>
<div>
<div><a class="knol-anchor-headings" name="9(2E)4(2E)3(2E)(C2)(A0)Reattaching_detached_objects"></a></p>
<h3>3. Reattaching detached objects</h3>
</div>
</div>
</div>
<p>The <tt>Lock()</tt> method allows the application to reassociate                 an unmodified object with a new session.</p>
<pre>//just reassociate:
sess.Lock(fritz, LockMode.None);
//do a version check, then reassociate:
sess.Lock(izi, LockMode.Read);
//do a version check, using SELECT ... FOR UPDATE, then reassociate:
sess.Lock(pk, LockMode.Upgrade);</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=84&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-updating-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate Tips: Criteria queries &amp; Queries in native SQL</title>
		<link>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-criteria-queries-queries-in-native-sql/</link>
		<comments>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-criteria-queries-queries-in-native-sql/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 11:45:14 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=81</guid>
		<description><![CDATA[Criteria queries HQL is extremely powerful but some people prefer to build queries dynamically, using an object oriented API, rather than embedding strings in their .NET code. For these people, NHibernate provides an intuitive ICriteria query API. ICriteria crit = session.CreateCriteria(typeof(Cat)); crit.Add( Expression.Eq("color", Eg.Color.Black) ); crit.SetMaxResults(10); IList cats = crit.List(); If you are uncomfortable with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=81&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><span style="color:#0000ff;">Criteria queries</span></h3>
<p>HQL is extremely powerful but some people prefer to build queries dynamically, using an object oriented API, rather than embedding strings in their .NET code. For these people, NHibernate provides an intuitive <tt>ICriteria</tt> query API.</p>
<pre>ICriteria crit = session.CreateCriteria(typeof(Cat));
crit.Add( Expression.Eq("color", Eg.Color.Black) );
crit.SetMaxResults(10);
IList cats = crit.List();</pre>
<p>If you are uncomfortable with SQL-like syntax, this is perhaps the easiest way to get started with NHibernate. This API is also more extensible than HQL. Applications might provide their own implementations of the <tt>ICriterion</tt> interface.</p>
<h3><span style="color:#0000ff;">Queries in native SQL</span></h3>
<p>You may express a query in SQL, using <tt>CreateSQLQuery()</tt>. You must enclose                 SQL aliases in braces.</p>
<pre>IList cats = session.CreateSQLQuery(
    "SELECT {cat.*} FROM CAT {cat} WHERE ROWNUM&lt;10",
    "cat",
    typeof(Cat)
).List();
IList cats = session.CreateSQLQuery(
    "SELECT {cat}.ID AS {cat.Id}, {cat}.SEX AS {cat.Sex}, " +
           "{cat}.MATE AS {cat.Mate}, {cat}.SUBCLASS AS {cat.class}, ... " +
    "FROM CAT {cat} WHERE ROWNUM&lt;10",
    "cat",
    typeof(Cat)
).List()</pre>
<p>SQL queries may contain named and positional parameters, just like NHibernate queries.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/81/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=81&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-criteria-queries-queries-in-native-sql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate Tips: The IQuery interface</title>
		<link>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-the-iquery-interface/</link>
		<comments>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-the-iquery-interface/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 11:41:35 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=78</guid>
		<description><![CDATA[If you need to specify bounds upon your result set (the maximum number of rows you want to retrieve and / or the first row you want to retrieve) you should obtain an instance of NHibernate.IQuery: IQuery q = sess.CreateQuery("from DomesticCat cat"); q.SetFirstResult(20); q.SetMaxResults(10); IList cats = q.List(); You may even define a named query [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=78&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you need to specify bounds upon your result set (the maximum number of rows you want to retrieve and / or the first row you want to retrieve) you should obtain an instance of <tt>NHibernate.IQuery</tt>:</p>
<pre>IQuery q = sess.CreateQuery("from DomesticCat cat");
q.SetFirstResult(20);
q.SetMaxResults(10);
IList cats = q.List();</pre>
<p>You may even define a named query in the mapping document. (Remember to use a                 <tt>CDATA</tt> section if your query contains characters that could                 be interpreted as markup.)</p>
<pre>&lt;query name="Eg.DomesticCat.by.name.and.minimum.weight"&gt;&lt;![CDATA[
    from Eg.DomesticCat as cat
        where cat.Name = ?
        and cat.Weight &gt; ?
] ]&gt;&lt;/query&gt;
IQuery q = sess.GetNamedQuery("Eg.DomesticCat.by.name.and.minimum.weight");
q.SetString(0, name);
q.SetInt32(1, minWeight);
IList cats = q.List();</pre>
<p>The query interface supports the use of named parameters. Named parameters are identifiers of the form <tt>:name</tt> in the query string.                 There are methods on <tt>IQuery</tt> for binding values to named or positional parameters. NHibernate numbers parameters from zero. The advantages of named parameters are:</p>
<div>
<ul>
<li>named parameters are insensitive to the order they occur in the query string</li>
<li>they may occur multiple times in the same query</li>
<li>they are self-documenting</li>
</ul>
</div>
<pre>//named parameter (preferred)
IQuery q = sess.CreateQuery("from DomesticCat cat where cat.Name = :name");
q.SetString("name", "Fritz");
IEnumerable cats = q.Enumerable();
//positional parameter
IQuery q = sess.CreateQuery("from DomesticCat cat where cat.Name = ?");
q.SetString(0, "Izi");
IEnumerable cats = q.Enumerable();
//named parameter list
IList names = new ArrayList();
names.Add("Izi");
names.Add("Fritz");
IQuery q = sess.CreateQuery("from DomesticCat cat where cat.Name in (:namesList)");
q.SetParameterList("namesList", names);
IList cats = q.List();</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=78&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-the-iquery-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate Tips : Querying</title>
		<link>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-querying/</link>
		<comments>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-querying/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 11:27:19 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=74</guid>
		<description><![CDATA[If you don&#8217;t know the identifier(s) of the object(s) you are looking for, use the Find() methods of ISession. NHibernate supports a simple but powerful object oriented query language. IList cats = sess.Find( "from Cat as cat where cat.Birthdate = ?", date, NHibernateUtil.Date ); IList mates = sess.Find( "select mate from Cat as cat join [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=74&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t know the identifier(s) of the object(s) you are looking for, use the <tt>Find() </tt> methods of <tt>ISession</tt>. NHibernate supports a simple but powerful object              oriented query language.</p>
<pre>IList cats = sess.Find(
    "from Cat as cat where cat.Birthdate = ?",
    date,
    NHibernateUtil.Date
);

IList mates = sess.Find(
    "select mate from Cat as cat join cat.Mate as mate " +
    "where cat.name = ?",
    name,
    NHibernateUtil.String
);

IList cats = sess.Find( "from Cat as cat where cat.Mate.Birthdate is null" );

IList moreCats = sess.Find(
    "from Cat as cat where " +
    "cat.Name = 'Fritz' or cat.id = ? or cat.id = ?",
    new object[] { id1, id2 },
    new IType[] { NHibernateUtil.Int64, NHibernateUtil.Int64 }
);

IList mates = sess.Find(
    "from Cat as cat where cat.Mate = ?",
    izi,
    NHibernateUtil.Entity(typeof(Cat))
);

IList problems = sess.Find(
    "from GoldFish as fish " +
    "where fish.Birthday &gt; fish.Deceased or fish.Birthday is null"
);</pre>
<p>The second argument to <tt>Find()</tt> accepts an object or array of objects. The third argument accepts a NHibernate type or array of NHibernate types. These given types are used to bind the given objects to the <tt>?</tt> query placeholders (which map to input             parameters of an ADO.NET <tt>IDbCommand</tt>). Just as in ADO.NET, you should use this binding mechanism in preference to string manipulation.</p>
<p>The <tt>NHibernateUtil</tt> class defines a number of static methods and constants, providing access to most of the built-in types, as instances of <tt>NHibernate.Type.IType</tt>.</p>
<p>If you expect your query to return a very large number of objects, but you don&#8217;t expect to use them all, you might get better performance from the <tt>Enumerable()</tt> methods, which return a             <tt>System.Collections.IEnumerable</tt>. The iterator will load objects on demand, using the identifiers returned by an initial SQL query (n+1 selects total).</p>
<pre>// fetch ids
IEnumerable en = sess.Enumerable("from eg.Qux q order by q.Likeliness");
foreach ( Qux qux in en )
{
    // something we couldnt express in the query
    if ( qux.CalculateComplicatedAlgorithm() ) {
        // dont need to process the rest
        break;
    }
}</pre>
<p>The <tt>Enumerable()</tt> method also performs better if you expect that many of the objects are already loaded and cached by the session, or if the query results contain the same objects many times. (When no data is cached or repeated, <tt>Find()</tt> is almost always faster.) Heres an example of a query that should be             called using <tt>Enumerable()</tt>:</p>
<pre>IEnumerable en = sess.Enumerable(
    "select customer, product " +
    "from Customer customer, " +
    "Product product " +
    "join customer.Purchases purchase " +
    "where product = purchase.Product"
);</pre>
<p>Calling the previous query using <tt>Find()</tt> would return a very             large ADO.NET result set containing the same data many times.</p>
<p>NHibernate queries sometimes return tuples of objects, in which case each tuple is returned as an array:</p>
<pre>IEnumerable foosAndBars = sess.Enumerable(
    "select foo, bar from Foo foo, Bar bar " +
    "where bar.Date = foo.Date"
);
foreach (object[] tuple in foosAndBars)
{
    Foo foo = tuple[0]; Bar bar = tuple[1];
    ....
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=74&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/03/nhibernate-tips-querying/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Tutorial: Get,Set properties for object.</title>
		<link>http://baondp.wordpress.com/2009/04/03/c-tutorial-getset-properties-for-object/</link>
		<comments>http://baondp.wordpress.com/2009/04/03/c-tutorial-getset-properties-for-object/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 02:22:12 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C# Tutorial]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=68</guid>
		<description><![CDATA[I lazy when do one work every coding, that&#8217;s copy DAO to Entity in Hibernate (my company&#8217;s framework) please dont ask why do that ^^. Here is may code: static void Main(string[] args) { User dto = new User(); //dto.ID = new Guid(); dto.FirstName = "Bao"; dto.MiddleName = "Duc Phuc"; dto.LastName = "Nguyen"; UserBE be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=68&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I lazy when do one work every coding, that&#8217;s copy DAO to Entity in Hibernate (my company&#8217;s framework) please dont ask why do that ^^.</p>
<p>Here is may code:</p>
<pre>static void Main(string[] args)
{
User dto = new User();
//dto.ID = new Guid();
dto.FirstName = "Bao";
dto.MiddleName = "Duc Phuc";
dto.LastName = "Nguyen";

UserBE be = new UserBE();
be = ConvertDTOtoBE&lt;User, UserBE&gt;(dto, be) as UserBE;

PropertyInfo[] pi1 = typeof(User).GetProperties();
PropertyInfo[] pi2 = typeof(UserBE).GetProperties();
Console.WriteLine(typeof(User).Name);
foreach (PropertyInfo pi in pi1)
{
Console.WriteLine(pi.Name + " : " + pi.GetValue(dto, null));
}
Console.WriteLine("\n" + typeof(UserBE).Name);
foreach (PropertyInfo pi in pi2)
{
Console.WriteLine(pi.Name + " : " + pi.GetValue(be, null));
}
Console.WriteLine();
}

public static T2 ConvertDTOtoBE&lt;T1, T2&gt;(T1 t1, T2 t2)
where T2:class,new()
{
//T2 t2 = new T2();
t2 = new T2();
Type type1 = typeof(T1);

PropertyInfo[] pi1 = type1.GetProperties();
PropertyInfo[] pi2 = typeof(T2).GetProperties();
PropertyInfo piTmp;
foreach (PropertyInfo pi in pi1)
{
piTmp = pi2.FirstOrDefault(p =&gt; p.Name == pi.Name);
if (piTmp != null &amp;&amp; piTmp.CanWrite &amp;&amp; piTmp.PropertyType.Equals(pi.PropertyType))
{
piTmp.SetValue(t2, pi.GetValue(t1, null),null);
//Console.WriteLine(pi.Name + " : " + pi.GetValue(t1, null));
}
}
return t2;
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=68&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/03/c-tutorial-getset-properties-for-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Tutorial &#8211; Using Reflection to Get Object Information</title>
		<link>http://baondp.wordpress.com/2009/04/02/c-tutorial-using-reflection-to-get-object-information/</link>
		<comments>http://baondp.wordpress.com/2009/04/02/c-tutorial-using-reflection-to-get-object-information/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 06:26:53 +0000</pubDate>
		<dc:creator>baondp</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C# Tutorial]]></category>

		<guid isPermaLink="false">http://baondp.wordpress.com/?p=60</guid>
		<description><![CDATA[public class MyObject { //public fields public string myStringField; public int myIntField; public MyObject myObjectField; //public properties public string MyStringProperty { get; set; } public int MyIntProperty { get; set; } public MyObject MyObjectProperty { get; set; } //public events public event EventHandler MyEvent1; public event EventHandler MyEvent2; } To get a list of public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=60&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="geshifilter">
<pre>
<div class="csharp geshifilter-csharp"><span style="color:#0600ff;">public</span> <span style="color:#0600ff;">class</span> MyObject
<span style="color:#000000;">{</span>
<span style="color:#008000;font-style:italic;">//public fields</span>
<span style="color:#0600ff;">public</span> <span style="color:#0600ff;">string</span> myStringField<span style="color:#000000;">;</span>
<span style="color:#0600ff;">public</span> <span style="color:#0600ff;">int</span> myIntField<span style="color:#000000;">;</span>
<span style="color:#0600ff;">public</span> MyObject myObjectField<span style="color:#000000;">;</span></div>
<div class="csharp geshifilter-csharp">

<span style="color:#008000;font-style:italic;">//public properties</span>
<span style="color:#0600ff;">public</span> <span style="color:#0600ff;">string</span> MyStringProperty <span style="color:#000000;">{</span> <span style="color:#0600ff;">get</span><span style="color:#000000;">;</span> <span style="color:#0600ff;">set</span><span style="color:#000000;">;</span> <span style="color:#000000;">}</span>
<span style="color:#0600ff;">public</span> <span style="color:#0600ff;">int</span> MyIntProperty <span style="color:#000000;">{</span> <span style="color:#0600ff;">get</span><span style="color:#000000;">;</span> <span style="color:#0600ff;">set</span><span style="color:#000000;">;</span> <span style="color:#000000;">}</span>
<span style="color:#0600ff;">public</span> MyObject MyObjectProperty <span style="color:#000000;">{</span> <span style="color:#0600ff;">get</span><span style="color:#000000;">;</span> <span style="color:#0600ff;">set</span><span style="color:#000000;">;</span> <span style="color:#000000;">}</span>

<span style="color:#008000;font-style:italic;">//public events</span>
<span style="color:#0600ff;">public</span> <span style="color:#0600ff;">event</span> <span style="color:#008080;">EventHandler</span> MyEvent1<span style="color:#000000;">;</span>
<span style="color:#0600ff;">public</span> <span style="color:#0600ff;">event</span> <span style="color:#008080;">EventHandler</span> MyEvent2<span style="color:#000000;">;</span>
<span style="color:#000000;">}</span></div>
</pre>
</div>
<div class="csharp geshifilter-csharp">
<p>To get a list of public fields in an object, we&#8217;ll use Type&#8217;s <a href="http://msdn.microsoft.com/en-us/library/ch9714z3.aspx">GetField</a> method:</p>
<div class="geshifilter">
<pre>
<div class="csharp geshifilter-csharp"><span style="color:#008080;">Type</span> myObjectType <span style="color:#296d26;">=</span> <span style="color:#0600ff;">typeof</span><span style="color:#000000;">(</span><span style="color:#000000;">MyObject</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span></div>

<span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">FieldInfo</span><span style="color:#000000;">[</span><span style="color:#000000;">]</span> fieldInfo <span style="color:#296d26;">=</span> myObjectType.<span style="color:#000000;">GetFields</span><span style="color:#000000;">(</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>

<span style="color:#0600ff;">foreach</span> <span style="color:#000000;">(</span><span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">FieldInfo</span> info <span style="color:#0600ff;">in</span> fieldInfo<span style="color:#000000;">)</span>
<span style="color:#008080;">Console</span>.<span style="color:#000000;">WriteLine</span><span style="color:#000000;">(</span>info.<span style="color:#000000;">Name</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>

<span style="color:#008000;font-style:italic;">// Output:</span>
<span style="color:#008000;font-style:italic;">// myStringField</span>
<span style="color:#008000;font-style:italic;">// myIntField</span>
<span style="color:#008000;font-style:italic;">// myObjectField</span></pre>
</div>
<p>An important thing to note here is that the fields are not guaranteed to come out in any particular order. If you use GetFields, you should never depend on the order being consistent. The <a href="http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.aspx">FieldInfo</a> class that gets returned actually contains a lot of useful information. It also contains the ability to set that field on an instance of MyObject &#8211; that&#8217;s where the real power comes in.</p>
<div class="geshifilter">
<pre>
<div class="csharp geshifilter-csharp">MyObject myObjectInstance <span style="color:#296d26;">=</span> <span style="color:#0600ff;">new</span> MyObject<span style="color:#000000;">(</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span></div>

<span style="color:#0600ff;">foreach</span> <span style="color:#000000;">(</span><span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">FieldInfo</span> info <span style="color:#0600ff;">in</span> fieldInfo<span style="color:#000000;">)</span>
<span style="color:#000000;">{</span>
<span style="color:#0600ff;">switch</span> <span style="color:#000000;">(</span>info.<span style="color:#000000;">Name</span><span style="color:#000000;">)</span>
<span style="color:#000000;">{</span>
<span style="color:#0600ff;">case</span> <span style="color:#ff0000;">"myStringField"</span><span style="color:#296d26;">:</span>
info.<span style="color:#000000;">SetValue</span><span style="color:#000000;">(</span>myObjectInstance, <span style="color:#ff0000;">"string value"</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>
<span style="color:#0600ff;">break</span><span style="color:#000000;">;</span>
<span style="color:#0600ff;">case</span> <span style="color:#ff0000;">"myIntField"</span><span style="color:#296d26;">:</span>
info.<span style="color:#000000;">SetValue</span><span style="color:#000000;">(</span>myObjectInstance, <span style="color:#000000;">42</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>
<span style="color:#0600ff;">break</span><span style="color:#000000;">;</span>
<span style="color:#0600ff;">case</span> <span style="color:#ff0000;">"myObjectField"</span><span style="color:#296d26;">:</span>
info.<span style="color:#000000;">SetValue</span><span style="color:#000000;">(</span>myObjectInstance, myObjectInstance<span style="color:#000000;">)</span><span style="color:#000000;">;</span>
<span style="color:#0600ff;">break</span><span style="color:#000000;">;</span>
<span style="color:#000000;">}</span>
<span style="color:#000000;">}</span>

<span style="color:#008000;font-style:italic;">//read back the field information</span>
<span style="color:#0600ff;">foreach</span> <span style="color:#000000;">(</span><span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">FieldInfo</span> info <span style="color:#0600ff;">in</span> fieldInfo<span style="color:#000000;">)</span>
<span style="color:#000000;">{</span>
<span style="color:#008080;">Console</span>.<span style="color:#000000;">WriteLine</span><span style="color:#000000;">(</span>info.<span style="color:#000000;">Name</span> <span style="color:#296d26;">+</span> <span style="color:#ff0000;">": "</span> <span style="color:#296d26;">+</span>
info.<span style="color:#000000;">GetValue</span><span style="color:#000000;">(</span>myObjectInstance<span style="color:#000000;">)</span>.<span style="color:#000000;">ToString</span><span style="color:#000000;">(</span><span style="color:#000000;">)</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>
<span style="color:#000000;">}</span>

<span style="color:#008000;font-style:italic;">// Output:</span>
<span style="color:#008000;font-style:italic;">// myStringField: string value</span>
<span style="color:#008000;font-style:italic;">// myIntField: 42</span>
<span style="color:#008000;font-style:italic;">// myObjectField: MyObject</span></pre>
</div>
</div>
<p>Combining this ability with the ability to <a href="http://www.switchonthecode.com/tutorials/csharp-tutorial-method-attributes-and-reflection">create custom attributes</a> provides a framework on which almost any serialization technique can be built.</p>
<p>Properties and events are retrieved almost identically to fields:</p>
<div class="geshifilter">
<pre>
<div class="csharp geshifilter-csharp"><span style="color:#008080;">Type</span> myObjectType <span style="color:#296d26;">=</span> <span style="color:#0600ff;">typeof</span><span style="color:#000000;">(</span><span style="color:#000000;">MyObject</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span></div>

<span style="color:#008000;font-style:italic;">//Get public properties</span>
<span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">PropertyInfo</span><span style="color:#000000;">[</span><span style="color:#000000;">]</span> propertyInfo <span style="color:#296d26;">=</span>
myObjectType.<span style="color:#000000;">GetProperties</span><span style="color:#000000;">(</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>

<span style="color:#0600ff;">foreach</span> <span style="color:#000000;">(</span><span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">PropertyInfo</span> info <span style="color:#0600ff;">in</span> propertyInfo<span style="color:#000000;">)</span>
<span style="color:#008080;">Console</span>.<span style="color:#000000;">WriteLine</span><span style="color:#000000;">(</span>info.<span style="color:#000000;">Name</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>

<span style="color:#008000;font-style:italic;">// Output:</span>
<span style="color:#008000;font-style:italic;">// MyStringProperty</span>
<span style="color:#008000;font-style:italic;">// MyIntProperty</span>
<span style="color:#008000;font-style:italic;">// MyObjectProperty</span>

<span style="color:#008000;font-style:italic;">//Get events</span>
<span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">EventInfo</span><span style="color:#000000;">[</span><span style="color:#000000;">]</span> eventInfo <span style="color:#296d26;">=</span>
myObjectType.<span style="color:#000000;">GetEvents</span><span style="color:#000000;">(</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>

<span style="color:#0600ff;">foreach</span> <span style="color:#000000;">(</span><span style="color:#008080;">System</span>.<span style="color:#000000;">Reflection</span>.<span style="color:#008080;">EventInfo</span> info <span style="color:#0600ff;">in</span> eventInfo<span style="color:#000000;">)</span>
<span style="color:#008080;">Console</span>.<span style="color:#000000;">WriteLine</span><span style="color:#000000;">(</span>info.<span style="color:#000000;">Name</span><span style="color:#000000;">)</span><span style="color:#000000;">;</span>

<span style="color:#008000;font-style:italic;">// Output:</span>
<span style="color:#008000;font-style:italic;">// MyEvent1</span>
<span style="color:#008000;font-style:italic;">// MyEvent2</span></pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baondp.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baondp.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baondp.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baondp.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baondp.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baondp.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baondp.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baondp.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=baondp.wordpress.com&amp;blog=6643145&amp;post=60&amp;subd=baondp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://baondp.wordpress.com/2009/04/02/c-tutorial-using-reflection-to-get-object-information/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adcfaa320da268171b73ec08d8106da1?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">baondp</media:title>
		</media:content>
	</item>
	</channel>
</rss>
