September 2007 - Posts

Time to say good bye to my SgDotNet's Blog

Dear all,

  I had been thinking a lot. If you notice my earlier post on "3 months no blogging", I did mentioned something about changing a new blog. I was waiting for this, and finally I got it.

   I will like to take this opportunity to thanks the team for creating a blog for me in SgDotNet. I appreciated this so much. I will be moving into a new blog. Check this out http://weblogs.asp.net/wenching/default.aspx

  I am grateful to Joe and I will try my best to blog there as often as possible.

Thank you.

Posted by chuawenching with 5 comment(s)
Filed under:

Presented C# 3.0, LINQ and Visual Studio 2008 Beta 2 in office

Wow. It was challenging. I received a lot of questions especially on the new features of C# 3.0.

LINQ is quite new to them. They found it hard to accept writing query in codes and not relying on Stored Procedures.

Then there were questions ORM vs Stored Procedures.

Looks like I will focus a lot on LINQ and hopefully when my next presentation on the same topic, I am able to convince all of them.

Posted by chuawenching with no comments

Missing FuncletExpression and LiftExpression in Visual Studio 2008 Beta 2

I believe this is good to share this to everyone. Basically I find nothing about this in the search engine. Furthermore, you can find about Mono or some very old post. Not in Beta 2.

Anyway I was looking for a replacement for FuncletExpression and LiftExpression in Visual Studio 2008 Beta 2. I am actually trying to migrate the NHibernate.LINQ (http://blogs.magiconsoftware.com/files/folders/8/download.aspx) example to support VS 2008 Beta 2. I emailed Ayende Rahien but he asked me to refer to the release notes.

So I decided to post in the C# Mailing List. Below is the response:

// Response from Microsoft

Chua Wen Ching –

There are no direct replacements for these two Expression Tree nodes in the Beta2 or RTM versions of the LINQ API – but uses of either should be possible by other means:

-          In place of FuncletExpressions, you will typically just use a ConstantExpression with the pre-evaluated version of the value that node represents. 

-          In place of LiftExpressions, the other expression tree nodes, such as BinaryExpression and UnaryExpression now automatically handle lifting for you.  For example, if passed nodes of nullable type as arguments, the Expression.Add(…) constructor will generate a BinaryExpression which has Lifted==true.

Hope that helps.

Thanks,

Luke

///////////////////

Cheers.

"NHibernate Part 1: Hello World with NHibernate" article - Getting to work in Microsoft SQL Server 2005

You can check out this article here http://sdesmedt.wordpress.com/2006/04/05/hello-world-with-nhibernate/

I can say it is really easy to get started. However if you follow the codes in there, you will start to realize to face problems getting it running.

I will provide some tips to get it work.

1)      Requires Virtual on each property

As on original article:

public class MessageProvider

{

    private int id;

    private string message;

 

    public MessageProvider()

    {

 

    }

 

    public int Id

    {

        get { return id; }

        set { id = value; }

    }

 

  

    public string Message

    {

        get { return message; }

        set { message = value; }

    }

}

Errors that you will get:

The following types may not be used as proxies:

TheData.MessageProvider: method get_Message should be virtual

TheData.MessageProvider: method get_Id should be virtual

TheData.MessageProvider: method set_Id should be virtual

TheData.MessageProvider: method set_Message should be virtual

Solution:

public class MessageProvider

{

    private int id;

    private string message;

 

    public virtual int Id

    {

        get { return id; }

        set { id = value; }

    }

 

  

    public virtual string Message

    {

        get { return message; }

        set { message = value; }

    }

}

You can remove the empty constructor. There is no reason to keep it there too.

2)      Hibernate-Mapping namespace

I check in search engine and I realize a lot of people are frustrated about this. Easy. If you are using NHibernate 1.2.0.4000

As on original article:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="property">

Solution:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property">

Change it from 2.0 to 2.2. It solves the problem.

3)      If you are using Microsoft SQL Server 2005

As on original article:

config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MySqlDialect");

Solution:

config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect");

Just to make sure you have the right settings for your database, do check at this link http://www.hibernate.org/361.html?cmd=comphist&histnode=2604

There is no updates for Microsoft SQL Server 2005 but it worked the same with Microsoft SQL Server 2000.

Just to add that you can do this:

config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @"Server=wenchingpc\sql2005;initial catalog=nhibernate_test;Integrated Security=SSPI;");

 

config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @"Server=wenchingpc\sql2005;initial catalog=nhibernate_test;User ID=sa;Password=sa;");

The 2nd one is not part of the url above. But it will work just fine J

The connection string is very important especially to execute the code below:

IList messages = session.CreateCriteria(typeof(TheData.MessageProvider)).List();

4)      How do you name the hbm.xml file?

You can name it anything that you want. As for this case, I have only one mapping file and a MessageProvider class. I will call it MessageProvider.hbm.xml.

Below is the actual source code:

** Take note, I will base on that article. So I have not implement any best practices. So readers who face problem from that article can refer it here.

MessageProvider.cs

using System;

using System.Collections.Generic;

using System.Text;

 

namespace TheData

{

    public class MessageProvider

    {

        private int id;

        private string message;

 

        public virtual int Id

        {

            get { return id; }

            set { id = value; }

        }

 

        public virtual string Message

        {

            get { return message; }

            set { message = value; }

        }  

    }

}

MessageProvider.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property">

      <class name="TheData.MessageProvider, HelloNHibernate" table="HelloWorld">

            <id name="Id">

                  <generator class="identity" />

            </id>

            <property name="Message" />

      </class>

</hibernate-mapping>

Program.cs (or MainClass.cs)

using System;

using System.Collections;

using NHibernate;

using NHibernate.Cfg;

 

namespace HelloNHibernate

{

    class Program

    {

        static void Main(string[] args)

        {

            Configuration config = new Configuration();

            config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");

            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect");

            //config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @"Server=wenchingpc\sql2005;initial catalog=nhibernate_test;Integrated Security=SSPI;");

            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @"Server=wenchingpc\sql2005;initial catalog=nhibernate_test;User ID=sa;Password=!pandu@;");

            config.AddAssembly("HelloNHibernate");

 

            ISessionFactory factory = config.BuildSessionFactory();

 

            try

            {

                ISession session = factory.OpenSession();

                IList messages = session.CreateCriteria(typeof(TheData.MessageProvider)).List();

 

                Console.WriteLine("No Messages: {0}\n", messages.Count);

 

                foreach (TheData.MessageProvider aMessage in messages)

                {

                    Console.WriteLine("Id: {0} - Message: {1}", aMessage.Id, aMessage.Message);

                }

 

                session.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

 

            Console.Read();

        }

    }

}

 

Hope you find it useful.  Thank you.

Posted by chuawenching with 6 comment(s)
Filed under: ,

3 months no blogging. What actually happens?

It had been 3 months not blogging. I could say I was busy with work and probably giving an excuse not to blog. Just to summarize what had happened the past 3 months J in no particular order

a)      Preparing on video shooting for techNation site. You can check the videos here http://www.technation.com.my/ Make sure you have Microsoft Silverlight installed.

b)      I was not involved in any development of the site but I was more to moral support and planning though to get it ready before Microsoft TechEd 2007 SEA. Gave 2 O’Reilly books to the 2 developers from ISA Technologies. Good work guys. The best part was the site was showcased in Silverlight.net. Check it here http://silverlight.net/Showcase/

c)       Spoke in .NET University for TechED 2007 SEA. Honestly speaking, it turned out quite bad. The reason as I was really sick the whole TechED 2007 SEA and I only managed to have access to the WCF slides on Monday. I needed to delivery on Wednesday. I had spoken to Microsoft to speak in either WPF or WF, however was assigned WCF. I would never speak on a topic which I had no experiences on. However there was something I learned from Doug Turnure from .NET University was to speak more so I could improve myself. I will love to speak in a developer track next year in TechED 2008 SEA.

d)      I was involved in the Malaysia Integrity Circle. The program was called TSAZAIC and I was in the 3rd batch. Bring Malaysian proud J Based on my colleague, I was one of the few ambassadors  (3 people selected by the CEO) to represent my company for this Integrity Circle in Malaysia

e)      I organized a few team building gatherings at office. Guess the morale of my colleagues increased more than before. Last time I only covered my own team which I was working in. But now it covered around 7 managers. Again I like to see everyone happy.

f)       Learn a few technologies and I guess you will see me blogging about it.

g)      Was deciding whether to create a site of my own so people can recognize me. Not sure yet on this one.

h)      Think more Solutions than just entirely on technology. Not only that I will pick up more skills other than just Information Technology – sales, marketing, HR, corp comm., etc. I was to bias on JavaFx thing. I will try my best not to be bias on any technologies.

i)        I was one of the 60 or 80 people (can’t remember the exact number) selected in the CEO Diamond Club for my company. Basically it was a program to recognize top performers for Quarter 1 and 2 in my company. Take note, my company has 800 employees. Very lucky and appreciate this. Managed to chat with the CEO. I was very happy.

j)        I got a call from a CEO one day and he enquired for advises on Windows Vista graphic driver issue. I gave a few suggestions and even commented on the UAC thing. I explained to him on the usage and he agreed with that. Why was this special? As you know everyone know the CEO and it was always hard for the CEO to remember you. Thanks god. This might not be anything to other people, but it was remarkable to me.

k)      Organized one of MIND community greatest event – impactful and meaningful. Even though we co-organized with iTrain on KL TechNite + MIND: Developers Rock, the contents and sponsors were managed by me J however I will like to thanks Mike, iTrain to reserve the venue. I managed to get 20 sponsors. Actually there were more but it was way too last minute. A piece of advice, look for sponsors at least 2 months ahead. The total sponsorship was RM 60,000 with 106 lucky draw items to be won. Wow.

l)        In this event, I was very lucky to get support from the MVP Lead Team for Southeast Asia. I found it lacking for companies to recognize their employees being MVPs in Malaysia. Not only are those Microsoft Developers in Malaysia not really aware of this program. Really hope I could lend some help to build awareness.

m)    I was interviewed by DotNetRocks for this event too but the interview was more focused on Communities in Malaysia. I managed to get the other 2 communities presidents and techNation president into this interview. It was fun. Mark Dunn praised me on the sponsorship. Got nice feedbacks from the speakers too. However the podcast is not released yet and I heard from Mark as it will be released somewhere in November 2007.

n)      As for the same event, I got 2 Full page editorial by PC.Com magazine. It was the 1st time I tagged along media. Thanks to Josh for the contacts and support. Without him, it wouldn’t happen to have this from PC.Com. I had submitted the event details to PC.Com and I really hoped they will publish it.

o)      I got a new desktop computer 2 months ago. It was the 2nd best specifications from Dell back then (Intel Core 2 Duo 2.66GHz, 2GB of Ram and NVidia GeForce 8600 GTS). I could say it was the best machine till today in office. Nevertheless, there were 2 issues. First I had to return by T60 laptop back and second I didn’t have a new monitor. Other than getting my new machine, I also helped my colleague Razie to obtain a powerful machine too.

p)      I had joined a new team in the current company. Thanks to my previous manager, Yang for the guidance in career and working opportunities. Now I am working with Megat. Looking ahead under his guidance.

q)      There are so many more which I can’t think off at the moment

I really hope I can give myself sometime to blog more. I have limitation to internet access, only able to access it in office. I have so many plans ahead on communities + career. Stay tuned J

Posted by chuawenching with no comments