Learning Silverlight
I wish to a rich user interface for my website. Well, HTML 5 is the best choice. But HTML 5 is still not easy to do some tasks, such as animations and charting. Then, Flash is the second best choice. A lot of platforms support this. But I need to learn it from scratch. In this case, Silverlight is a much better option. It is similar with WPF which I have learnt before.Moreover, the Silverlight is a component-based components. I can use some third-party controls to build the interface. Those third-party controls can be download from internet freely or just needs to pay a small amount of money. This can reduce the amount of coding. So, I choose to learn Silverlight
Silverlight 4 Toolkit - April 2010 - Unknown Namespace Error
I have installed Silverlight 4 Toolkit - April 2010. I tried to drop a component in a xaml. But I got an error,
"Unknown namespace http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit". I searched a solution for a while, but no luck at all! Finally, I got the cause I forgot to install Silverlight SDK4! I am so silly!
After I installed it, that works! Please remember set your visual studio project to use Silverlight 4 too!
Getting Row Count in NHibernate
Getting the row count of a table, that is easy in NHibernate. You can do it this way:
Code
| ICriteria criteria = CurrentSession.CreateCriteria<Member>(); | |
| criteria.Add(Expression.Eq("Code",code));       | |
| return (int)  criteria.List().Count; | 
But this is very heavy weighted. You are retrieving a whole list of objects!!!! But you just need to know the numbers of objects! You are wasting a lot of processing power!
You can do it this way. That is only getting a row count, just a number! Therefore, a "select count(*)" query is executed.
Code
| ICriteria criteria = CurrentSession.CreateCriteria<Member>(); | |
| criteria.Add(Expression.Eq("Code",code)); | |
| criteria.SetProjection(Projections.RowCount()); | |
| return (int)  criteria.UniqueResult(); | 
Inconsistency between windows by NHibernate.
I am writing a library management system for church. This is using Spring.Net and NHibnerante. But I faced a problem. After the user updated in a record window, the record in the main window did not get updated. I have read Spring.net Tutorial. That is nothings wrong. Even I forced the session flush. But that did not work. In the session of the record edit window, the fields are updated. When I jumped back to Main Window, the session is updated. Finally, I found the problem in the Transaction attribute. In the DAO, the code should be written like this:
Code
| [Transaction(ReadOnly = true)] | |
|         public IList<TEntity> GetAll() | |
|         { | 
And the update method
Code
| [Transaction] | |
|         public void Save(TEntity entity) | |
|         { | 
Validation Framework for .Net
I was looking for the way to do data validation for my church library management system, there are some good frameworks around. But I found they need to bind with other libraries. After I had spent some time to look around, then I found a library, calls Fluent Validation. They are very simple.
The validation can be done in this way:
Code
| ResourceValidator validator = new ResourceValidator(); | |
| ValidationResult results = validator.Validate(Resource); | |
|   | |
| if(!results.IsValid){ | |
| IList<ValidationFailure> failures = results.Errors | |
| ..... Do the error handling | |
| } | 
That is so simple, that is what I like!
Moreover, I downloaded their source codes. The structure and code are very very readable!
Lastly, it can be integrated with ASP.Net MVC!
