Test of blog publishing with Microsoft word 2007

This post is created using Microsoft word 2007. Let’s see if this makes blogging simpler. First of all some formatting bold
italic.

This is indented with tab.

  1. Some ordered item
  2. Another ordered item
  • A bullet list
  • Another element of the bullet list

Some weird code in VB.NET

    1 <AspNetHostingPermission(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal), _
    2  AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal), _
    3  ToolboxData(“<{0}:MultipleFieldsValidator runat=server></{0}:MultipleFieldsValidator>”)> _
    4 Public Class MultipleControlsValidator
    5    Inherits BaseValidator
    6 
    7    <Browsable(False), _
    8    EditorBrowsable(EditorBrowsableState.Never)> _
    9    Private Shadows Property SetFocusOnError() As Boolean
   10       Get
   11          Return False
   12       End Get
   13       Set(ByVal value As Boolean)
   14          Throw New NotSupportedException(“Cannot focus if we have more than one control to validate.”)
   15       End Set
   16    End Property

Some in C#


   38          Section section, Int32 linkId) {

   39 
   40          IUnitOfWork UoW = DataAccessProviderFactory.GetConversationUnitOfWork();
   41          Query Q = Query.CreateQuery(“Field.OwnerSection.mId”, section.Id, CriteriaOperator.Equal);
   42          Q.AddCriteria(“LinkId”, linkId, CriteriaOperator.Equal);
   43          Q.Operator = QueryOperator.And;
   44          IList<FieldData> result = UoW.GetByCriteria<FieldData>(Q);
   45          foreach (FieldData f in result) {
   46             UoW.Detach(f);
   47          }

And at last one image, this is the place where I work, my home…quite messy isn’t it?? 😀

Now let’s see if word can publish all this post in my new wordpress blog. 😀 😀 😀

The result for the code was quite messy, to have a good result I need to install a plugin for Visual Studio that gives me the option to “Copy as HTML” the code, and then once pasted in word 2007 I need to make some manual substitution for space and paragraph sign to have a good result. L

Alk.

Nhibernate bug?

I replicated a bug in nhibernate. I have a simple mapping for a simple class 

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Ca1" assembly="Ca1" default-lazy="false" default-access="property"> <class name="Ca1.Cliente" table="Clienti" > <id name="Id" column="Id" type="int" unsaved-value="0"> <generator class="identity" /> </id> <property name="Nome" type="String" column="Nome" insert="true" update="true" /> <property name="Indirizzo" type="String" column="Indirizzo" not-null="false" insert="true" update="true" /> <property name="LocalizedData" type="string" update="false" formula='(SELECT ClientiLoc.loctext FROM ClientiLoc WHERE ClientiLoc.clieid = Id and ClientiLoc.lang = :CultureFilter.LangId)'/> </class> </hibernate-mapping>

The only particular issue is that LocalizedData Property is a formula and takes data from another table that contains localized data, the current locale is specified as a filter. The problem originates from the following simple code

using (NHibernate.ISession session = Helpers.CreateSession()) { using (NHibernate.ITransaction tran = session.BeginTransaction()) { IFilter flt = session.EnableFilter("CultureFilter"); flt.SetParameter("LangId", "it"); ICriteria criteria = session.CreateCriteria(typeof(Ca1.Cliente)); //criteria.Add(NHibernate.Expression.Expression.Like("Nome", "Gian%")); criteria.Add(NHibernate.Expression.Expression.Eq("LocalizedData", "loc_it")); criteria.Add(NHibernate.Expression.Expression.Like("Nome", "Gian%")); IList<Ca1.Cliente> result = criteria.List<Cliente>(); Console.WriteLine("Retrieved {0} objects", result.Count); } }

This code simply creates a criteria filter to select a cliente entity that has both the name like ‘Gian%’ and the localized italian version equal to “loc_it”. All works well and the query generated intercepted by the sql profiler is.

exec sp_executesql N'SELECT this_.Id as Id0_0_, this_.Nome as Nome0_0_, this_.Indirizzo as Indirizzo0_0_, (SELECT ClientiLoc.loctext FROM ClientiLoc WHERE ClientiLoc.clieid = this_.Id and ClientiLoc.lang = @p0) as formula0_0_ FROM Clienti this_ WHERE (SELECT ClientiLoc.loctext FROM ClientiLoc WHERE ClientiLoc.clieid = this_.Id and ClientiLoc.lang = @p1) = @p2 and this_.Nome like @p3', N'@p0 nvarchar(2),@p1 nvarchar(2),@p2 nvarchar(6),@p3 nvarchar(5)',@p0=N'it',@p1=N'it',@p2=N'loc_it',@p3=N'Gian%'

The sql is quite messy, the query is OK but has a strange duplicated parameter ‘it’ even if I put only criteria for localized query. The real problem originates if the two criteria are inverted in order.

criteria.Add(NHibernate.Expression.Expression.Like("Nome", "Gian%")); criteria.Add(NHibernate.Expression.Expression.Eq("LocalizedData", "loc_it"));

This simple change breaks the query:

exec sp_executesql N'SELECT this_.Id as Id0_0_, this_.Nome as Nome0_0_, this_.Indirizzo as Indirizzo0_0_, (SELECT ClientiLoc.loctext FROM ClientiLoc WHERE ClientiLoc.clieid = this_.Id and ClientiLoc.lang = @p0) as formula0_0_ FROM Clienti this_ WHERE this_.Nome like @p1 and (SELECT ClientiLoc.loctext FROM ClientiLoc WHERE ClientiLoc.clieid = this_.Id and ClientiLoc.lang = @p2) = @p3', N'@p0 nvarchar(2),@p1 nvarchar(2),@p2 nvarchar(5),@p3 nvarchar(6)',@p0=N'it',@p1=N'it',@p2=N'Gian%',@p3=N'loc_it'

Even is sql is quite messy you can notice that the parameters order is wrong. The second criteria ClientiLoc.lang = @p2 is wrong because @p2 parameter does not contain the ‘it’ value but the ‘Gian%’ value.

This problem happens every time I have a formula property that use a filter. To work correctly, every criteria on filter property must be the first criteria in the criteria collection.

Alk.

Hello world!


Warning: sizeof(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 824

Warning: count(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 831

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!