Showing posts with label Databases. Show all posts
Showing posts with label Databases. Show all posts

Wednesday, November 18, 2009

Strange missing feature in CSharpCodeProvider

Currently I'm developing a database application for my university study that uses NHibernate. To enable lazy loading of results it is required for all members of mapped class to be virtual, so NHibernate can create proxy that will be replaced by actual object when required. And if class has events they also must be virtual because actually this is the same fields and methods.

On the other hand I've decided to generate those classes from XML definitions. On of the reasons for this is that this classes seems to be just and a set of properties, but they need to implement INotifiyPropertyChanged. I've decided to write a code generator using System.CodeDom members and to gain some experience at working with members of this namespace. However I've found that CSharpCodeProvider doesn't generate virtual events! Despite the fact that I set the appropriate attribute the event is still normal so NHibernate couldn't generate proxy. I've search through CSharpCodeProvider with Reflector and found that in the method GenerateEvent that generates code of event there is no call of a method OutputVTableModifier that inserts "virtual" keyword. VBCodeGenerator also doesn't generate virtual events.

So I wonder whether this is an intentional decision or the bug in the current .NET framework version (I have 3.5 SP 1). Actually I wasn't determined enough to search for this in the older version of .NET.

Saturday, March 07, 2009

NonLatin symbols in MySQL

While developing my recent program in databases I found that my program on C# doesn't work correctly with onlatin chracters. It happend with recent version MySql.Data connector assembly from MySql. But there was no such problem when I've used old ByteFX.Data assembly. But old connector has some other error (at least when it works with server 5.2). After digesting a problem I found how to make my program work correctly with nonlatin characters. The solution is obvious: program must use a unicode, so here I'll show that to change in configurations of database and cliet software.
  1. Encoding of connection must be Unicode. For this in connection string add this parameter: CharSet=utf8;
  2. Encoding of database also must be Unicode. In my.cnf file following variables must be set to utf8: default-character-set and chracter-set-server
  3. However this helped me only on Linux machine, on Windows MySQL crashed after string with such prameters. So on Windows I found another possible solution: specify charset only for database: CREATE DATABASE dbName CHARACTER SET = utf8;. This solution is more flexible than previous because it affects only your database and not whole server.