<?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: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-2831588114277891987</id><updated>2011-06-22T18:24:11.901+02:00</updated><title type='text'>Guillaume Lecanu's tech notes</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://lecanutechnotes.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2831588114277891987/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://lecanutechnotes.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Guillaume Lecanu</name><uri>http://www.blogger.com/profile/13636555916828940902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2831588114277891987.post-4406219117095005283</id><published>2009-01-22T13:35:00.002+01:00</published><updated>2009-01-22T22:27:00.523+01:00</updated><title type='text'>NHibernate Provider for Dynamic Data - Part 1</title><content type='html'>Dynamic Data supports LINQ To SQL and Entity Framework. There is also a provider for &lt;a href="http://weblogs.asp.net/fbouma/archive/2008/05/01/dynamic-data-and-3rd-party-o-r-mappers-is-a-fact.aspx" target="_self"&gt;LLBLGenLLBLGen&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;As a fan of it, I plan to plug NHibernate and Dynamic Data.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;font size="2"&gt;Is it possible ?&lt;/font&gt;&lt;/b&gt;&lt;br /&gt;A read a lot of articles on how to plug an ORM tool and Dynamic Data. There is two points that your ORM tool must provide :&lt;br /&gt;- A DataContext (Or ObjectContext) to provide a working session&lt;br /&gt;- Linq support&lt;br /&gt;- A Datasource control which has SelectParameters support (FransBouma)&lt;br /&gt;&lt;br /&gt;Since last week, NHibernate.Linq Alpha &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b7a3f537f4cbf46d" target="_self"&gt;is released&lt;/a&gt;. So we've got Linq Support and a new object NHibernateContext which could be our DataContext Object.&lt;br /&gt;So I need two components :&lt;br /&gt;- The Model Provider which will provide NHibernate methods to Dynamic Data&lt;br /&gt;- The Datasource control&lt;br /&gt;&lt;br /&gt;I've created a basic NHibernate solution to test my provider :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_7_6I_UTGn70/SXjZ1zzmHlI/AAAAAAAAAAk/kMVzlJkuXOI/s1600-h/solution.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 224px; height: 122px;" src="http://4.bp.blogspot.com/_7_6I_UTGn70/SXjZ1zzmHlI/AAAAAAAAAAk/kMVzlJkuXOI/s400/solution.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5294220880436928082" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is a short description :&lt;br /&gt;- &lt;b&gt;Entities&lt;/b&gt; : The entity class, with NHibernate mapping files. I've generated it with Mygeneration soft. Basing on the NHibernate.Linq examples, I've build my context class (with only one entity in it for the moment) :&lt;br /&gt;&lt;blockquote  style="background-color:#FFFFCC;font-family:courier;"&gt;&lt;span style="font-size:85%;color:#0000FF;"&gt;public &lt;span style="font-size:85%;color:#0000FF;"&gt;class &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#2B91AF;"&gt;WineNotesContext&lt;/span&gt;&lt;span style="font-size:85%;"&gt; : &lt;/span&gt;&lt;span style="font-size:85%;color:#2B91AF;"&gt;NHibernateContext    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;color:#0000FF;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; WineNotesContext(&lt;/span&gt;&lt;span style="font-size:85%;color:#2B91AF;"&gt;ISession&lt;/span&gt;&lt;span style="font-size:85%;"&gt; oSession) : &lt;/span&gt;&lt;span style="font-size:85%;color:#0000FF;"&gt;base&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(oSession)&lt;br /&gt;{&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;color:#0000FF;"&gt;public &lt;/span&gt;&lt;span style="font-size:85%;color:#2B91AF;"&gt;IOrderedQueryable&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;&lt;/span&gt;&lt;span style="font-size:85%;color:#2B91AF;"&gt;DtCountry&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt; Countries&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="font-size:85%;color:#0000FF;"&gt;get &lt;/span&gt;&lt;span style="font-size:85%;"&gt;{ &lt;/span&gt;&lt;span style="font-size:85%;color:#0000FF;"&gt;return&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Session.Linq&lt;&lt;/span&gt;&lt;span style="font-size:85%;color:#2B91AF;"&gt;DtCountry&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;(); }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;- &lt;b&gt;NHibDynamicData.Provider&lt;/b&gt; : This is the project where I wrote my NHibernate Model Provider.&lt;br /&gt;- &lt;b&gt;NHibDynamicData.Controls&lt;/b&gt; : This is the project where I wrote my NHibernate DataSource.&lt;br /&gt;- &lt;b&gt;TestLinqDD&lt;/b&gt; : A standard Linq To SQL Dynamic Data Website.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;font size="2"&gt;The Model Provider&lt;/font&gt;&lt;/b&gt;&lt;br /&gt;Based on the SimpleModelProvider from dynamic data release. You just have to include it on your global.asax on your dynamic data web site :&lt;br /&gt;&lt;blockquote  style="background-color:#FFFFCC;font-family:courier;"&gt;&lt;font size=2&gt;model.RegisterContext(&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000FF" size=2&gt;new &lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;NHibModelProvider&lt;/font&gt;&lt;font size=2&gt;(&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;typeof&lt;/font&gt;&lt;font size=2&gt;(&lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;WineNotesContext&lt;/font&gt;&lt;font size=2&gt;)), &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;new &lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;ContextConfiguration&lt;/font&gt;&lt;font size=2&gt;() { ScaffoldAllTables = &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;false &lt;/font&gt;&lt;font size=2&gt;});&lt;/font&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;font size="2"&gt;The DataSource Control&lt;/font&gt;&lt;/b&gt;&lt;br /&gt;Based on the LinqDataSource control. You have to replace standard LinqDataSource on your dynamic data pages by this control.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;font size="2"&gt;Customizing your entities&lt;/font&gt;&lt;/b&gt;&lt;br /&gt;You just have to use attributes. Here is the example of country entity :&lt;br /&gt;&lt;blockquote  style="background-color:#FFFFCC;font-family:courier;"&gt;&lt;br /&gt;&lt;font size=2&gt;[&lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;ScaffoldTable&lt;/font&gt;&lt;font size=2&gt;(&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;true&lt;/font&gt;&lt;font size=2&gt;)]&lt;br /&gt;[&lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;DisplayName&lt;/font&gt;&lt;font size=2&gt;(&lt;/font&gt;&lt;font color="#A31515" size=2&gt;"Country"&lt;/font&gt;&lt;font size=2&gt;)]&lt;br /&gt;[&lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;DisplayColumn&lt;/font&gt;&lt;font size=2&gt;(&lt;/font&gt;&lt;font color="#A31515" size=2&gt;"CtrName"&lt;/font&gt;&lt;font size=2&gt;)]&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;class &lt;/font&gt;&lt;/font&gt;&lt;font color="#2B91AF" size=2&gt;DtCountry &lt;/font&gt;&lt;br /&gt;&lt;font size=2&gt;	{&lt;/font&gt;&lt;/blockquote&gt;&lt;br /&gt;The entity will be used by the model (scaffold attribute) and will be shown by its display name. The same attributes are existing for each columns.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;font size="2"&gt;There are problems !!!&lt;/font&gt;&lt;/b&gt;&lt;br /&gt;...but I will fix it on next part of this article :&lt;br /&gt;- Deleting problems&lt;br /&gt;- Showing and updating foreign keys&lt;br /&gt;- Primary key detection problem, if it is not detected, MetaTable will be still on read-only mode !&lt;br /&gt;&lt;br /&gt;You can checkout this idea here : &lt;a href="http://speezo.unfuddle.com/svn/speezo_nhibdynamicdata/" target="_self"&gt;http://speezo.unfuddle.com/svn/speezo_nhibdynamicdata/&lt;/a&gt;&lt;br /&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2flecanutechnotes.blogspot.com%2f2009%2f01%2fdynamic-data-supports-linq-to-sql-and.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2flecanutechnotes.blogspot.com%2f2009%2f01%2fdynamic-data-supports-linq-to-sql-and.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2831588114277891987-4406219117095005283?l=lecanutechnotes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lecanutechnotes.blogspot.com/feeds/4406219117095005283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lecanutechnotes.blogspot.com/2009/01/dynamic-data-supports-linq-to-sql-and.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2831588114277891987/posts/default/4406219117095005283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2831588114277891987/posts/default/4406219117095005283'/><link rel='alternate' type='text/html' href='http://lecanutechnotes.blogspot.com/2009/01/dynamic-data-supports-linq-to-sql-and.html' title='NHibernate Provider for Dynamic Data - Part 1'/><author><name>Guillaume Lecanu</name><uri>http://www.blogger.com/profile/13636555916828940902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_7_6I_UTGn70/SXjZ1zzmHlI/AAAAAAAAAAk/kMVzlJkuXOI/s72-c/solution.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2831588114277891987.post-3032786211655267009</id><published>2009-01-13T12:11:00.011+01:00</published><updated>2009-01-13T13:24:21.406+01:00</updated><title type='text'>A DbMetadataProvider for ASP.NET Dynamic Data</title><content type='html'>&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;I read the article from &lt;a title="Marcin on Asp.net" href="http://blogs.msdn.com/marcinon/archive/2008/05/22/dynamic-data-samples-custom-metadata-providers.aspx" target="_self"&gt;Marcin on Asp.net&lt;/a&gt; on Dynamic Data Futures and custom metadata Providers. I wanted to implement his feature with a database persistance.&lt;br /&gt;For this example, I will store this properties :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Name of a table&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Name of a column&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Show or not a column&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-size:130%;"&gt;Database structure&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_7_6I_UTGn70/SWx3nfy_XOI/AAAAAAAAAAU/m8dzz1HJ-0o/s1600-h/DbStruct.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5290735182687460578" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 400px; CURSOR: hand; HEIGHT: 184px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_7_6I_UTGn70/SWx3nfy_XOI/AAAAAAAAAAU/m8dzz1HJ-0o/s400/DbStruct.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The structure is composed of two tables :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;ST_TYPEOBJET : which store the table attributes : TOBJ_NAME (Name of the table)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;ST_PROPRIETEOBJET : store the column attributes : PROB_NAME (Name of the column) and PROB_SHOW (Show it Y/N)&lt;/li&gt;&lt;span class="Apple-tab-span" style="WHITE-SPACE: pre"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/ul&gt;ST_TYPEOBJET have a column named T_OBJTYPENAME which store the corresponding Mapping type name (Full Name with assembly)&lt;br /&gt;ST_PROPRIETEOBJET havec a column named PROB_PROPERTYNAME which store the corresponding mapping property.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-size:130%;"&gt;Implementing a DbMetadataProvider&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This DbMetadataProvider is pretty simple. It parse the data in all tables (with LinqToEntities provider), then for each table it register the name with the InMemoryMetaDataManager.&lt;br /&gt;Then, for each property, it register the name and the scaffolding (Show it or not).&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="FONT-FAMILY: courier; BACKGROUND-COLOR: #ffffcc"&gt;///&lt;br /&gt;/// Database metadata Provider&lt;br /&gt;///&lt;br /&gt;public class DbMetadataProvider&lt;br /&gt;{&lt;br /&gt;  ///&lt;br /&gt;  /// Registering metadatas&lt;br /&gt;  ///&lt;br /&gt;  public static void RegisterMetadata()&lt;br /&gt;  {&lt;br /&gt;    Entities oContext = new DALBase.Entities();&lt;br /&gt;     foreach (ST_TYPEOBJET oTypeObjet in oContext.ST_TYPEOBJET.Include("ST_PROPRIETEOBJET"))&lt;br /&gt;     {&lt;br /&gt;       //Getting the type of the table in the mapping assembly&lt;br /&gt;      Type oType = System.Type.GetType(oTypeObjet.TOBJ_TYPENAME);&lt;br /&gt;&lt;br /&gt;      //Saving the name of the table as attribute&lt;br /&gt;      InMemoryMetadataManager.AddTableAttributes(oType,&lt;br /&gt;         new DisplayNameAttribute(oTypeObjet.TOBJ_NAME));      &lt;br /&gt;&lt;br /&gt;      foreach(ST_PROPRIETEOBJET oPropriete in oTypeObjet.ST_PROPRIETEOBJET)&lt;br /&gt;      {&lt;br /&gt;        //Getting the property&lt;br /&gt;        PropertyInfo oProperty = oType.GetProperty(oPropriete.PROB_PROPERTYNAME);&lt;br /&gt;&lt;br /&gt;        //Saving scaffolding&lt;br /&gt;        if (oPropriete.PROB_SHOW)&lt;br /&gt;        {&lt;br /&gt;          //Saving name&lt;br /&gt;          InMemoryMetadataManager.AddColumnAttributes(oProperty, new DisplayNameAttribute(oPropriete.PROB_NAME));&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;          InMemoryMetadataManager.AddColumnAttributes(oProperty, new ScaffoldColumnAttribute(false));&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-size:130%;"&gt;Call to the provider in global.asax&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You just have to specify wich metadataprovider you will use with your model in the global.asax of your web site.&lt;br /&gt;Here, you specify the InMemoryMetadataProvider as the MetadataProviderFactory :&lt;br /&gt;&lt;blockquote style="FONT-FAMILY: courier; BACKGROUND-COLOR: #ffffcc"&gt;model.RegisterContext(typeof(Entities), new ContextConfiguration()&lt;br /&gt;{&lt;br /&gt;  ScaffoldAllTables = true,&lt;br /&gt;  MetadataProviderFactory = (type =&gt; new InMemoryMetadataTypeDescriptionProvider(type, new AssociatedMetadataTypeTypeDescriptionProvider(type)))&lt;br /&gt;});&lt;/blockquote&gt;&lt;br /&gt;Then, you load here all your metadatas :&lt;br /&gt;&lt;blockquote style="FONT-FAMILY: courier; BACKGROUND-COLOR: #ffffcc"&gt;DbMetadataProvider.RegisterMetadata();&lt;/blockquote&gt;&lt;br /&gt;That's it.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2flecanutechnotes.blogspot.com%2f2009%2f01%2fi-read-article-from-marcin-on-asp.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2flecanutechnotes.blogspot.com%2f2009%2f01%2fi-read-article-from-marcin-on-asp.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2831588114277891987-3032786211655267009?l=lecanutechnotes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lecanutechnotes.blogspot.com/feeds/3032786211655267009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lecanutechnotes.blogspot.com/2009/01/i-read-article-from-marcin-on-asp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2831588114277891987/posts/default/3032786211655267009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2831588114277891987/posts/default/3032786211655267009'/><link rel='alternate' type='text/html' href='http://lecanutechnotes.blogspot.com/2009/01/i-read-article-from-marcin-on-asp.html' title='A DbMetadataProvider for ASP.NET Dynamic Data'/><author><name>Guillaume Lecanu</name><uri>http://www.blogger.com/profile/13636555916828940902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_7_6I_UTGn70/SWx3nfy_XOI/AAAAAAAAAAU/m8dzz1HJ-0o/s72-c/DbStruct.JPG' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
