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!
C# codes examples
I found the best way to learn a programming is reading example codes. So, I found this website,Microsoft All-In-One Code Framework, is very useful. Roughly, it got hundreds of example codes. THIS IS VERY COOL!
Error Message :"The type 'TEntity' must be a reference type in order to use it as parameter 'T' in the generic type or method 'XXXXX' (CS0452) -"
I got a line of code like this:
Code
public class HibnerateRepository<TEntity, TId> : IRepository<TEntity, TId> | |
...... | |
public IList<TEntity> GetAll() |
That sounds alright, but I got an Error Message :"The type 'TEntity' must be a reference type in order to use it as parameter 'T' in the generic type or method 'XXXXX' (CS0452) -".
Well, that is a common mistake and easy to fix.
Code
public class HibnerateRepository<TEntity, TId> : IRepository<TEntity, TId> where TEntity:class | |
...... | |
public IList<TEntity> GetAll() |
SharpDevelop 4.0
Visual Studio 2010 is in the market for a little while. That sounds like no opensource alternative for .Net 4.0 until now. SharpDevelop 4.0 Beta 1 is released. I have tried that. So far, my first impression is slower. I guess that is because the UI is heavy rewritten in WPF. I think most of people will agree WPF got a better appearance and runs slower. But it got a feature I want for long time. Windows forms designer for WPF. Now, you can use the form desginer to edit xaml. That's great! By the way, in release notes, they do not recommend to use the form designer for editing .net 2.0 winfrom files. I tried that, so far, I have not faced any major issues. Well, they don't recommend that, I think you should not do that.
Lastly, so far, I am very happy to the new version. It looks better and got more features!
