I am trying to hydrate a list of ~400 business objects and the performance becomes very slow when it needs to hydrate strings. It's taking in excess of 20secs to hydrate the 400 objects.
EDIT
We are using MySQL 5.1 and dotConnect for MySQL v5.0.12 as the data provider http://www.devart.com/dotconnect/mysql/
I did some benchmarks to narrow it down to the string types causing the problems. I started measuring the time from record 2 to n to ignore the time that might get taken up loading other assemblies.
The following code hydrates 1 object in 0ms
objUserInfo.PortalID = portalId
objUserInfo.IsSuperUser = Convert.ToBoolean(dr("IsSuperUser"))
objUserInfo.UserID = Convert.ToInt32(dr("UserID"))
This also hydrates 1 object in 0ms
objUserInfo.PortalID = portalId
objUserInfo.IsSuperUser = Convert.ToBoolean(dr("IsSuperUser"))
objUserInfo.UserID = Convert.ToInt32(dr("UserID"))
objUserInfo.Firstname = "FirstName"
However as soon as i do the convert on the datareader object to a string it takes an average of 53ms
objUserInfo.PortalID = portalId
objUserInfo.IsSuperUser = Convert.ToBoolean(dr("IsSuperUser"))
objUserInfo.UserID = Convert.ToInt32(dr("UserID"))
objUserInfo.Firstname = Convert.ToString(dr("FirstName"))
I also tried hydrating 2 strings and strangley it doesn't blow the performance out nearly as much as 1 string? The following only takes an average of 57ms to hydrate 1 object
objUserInfo.PortalID = portalId
objUserInfo.IsSuperUser = Convert.ToBoolean(dr("IsSuperUser"))
objUserInfo.UserID = Convert.ToInt32(dr("UserID"))
objUserInfo.Firstname = Convert.ToString(dr("FirstName"))
objUserInfo.LastName = Convert.ToString(dr("LastName"))
I know that a lot of people use the above syntax to hydrate business objects. Is there a more efficient/faster way to do this?
EDIT Just did another test which was to do a directcast on a string and it produces the same slow speeds :( 53ms just to do the cast.
objUserInfo.FirstName = DirectCast("alex", String)