I like this post most regarding global error handling.
January 2012 M T W T F S S « Dec 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Controls
-
I like this post most regarding global error handling.
When you do a search on ?SingalR”, you are most likely to get GitHub site or Scott Hanselman’s blog. I got those two as first two items. Since there aren’t many tutorials, how to and etc or at least still hard to find, I am writing this post as a record to myself so that I don’t have to go on and do those search again.
I am not going to claim that I will come back and update this entry every day or a week. But as of today, it’s where I looked.
Scott Hanselman – Post
This is one of the very first ones (as far as I know) and to get the example working (high level) I had to go through comments to find out that
Â
was missing.
Another obvious place is of course Wiki in Git Hub.
And so far I have found this example to be pretty good esp it has successfully implemented IDisconnect which I am still struggling to make it work. I suspect this is due to my SignalR being older version. Anyway here is the link and it works pretty good.
Build a user map with SingalR and Bing
I nearly pulled all my hair because of this problem. I knew all my parameter types were correct and when I ran the sproc in database it runs fine.
After some search the solution that worked for me was found here at stackoverflow.
http://stackoverflow.com/questions/4098668/odp-net-parameter-problem-with-uint-datatype
By default, Odp.net parameters are passed by position while my code was assuming it was by name.
NHiberate is wonderful. Being a newbie, I have at times struggled with some very simple error messages.
I came across this issue while I was trying to delete items from a collection of child objects.
In my mapping, Order has a bag of Orderlines and Orderline has a “navigation property” Order. My application allows amending orderlines or even delete them if they are not processed yet. While deleting I got the deleted object would be re-saved by cascade (remove deleted object from associations) because my cascade was set to “update-save”. Like the error suggested I removed the orderline from order before calling delete.
like this
order.Orderlines.Remove(orderline); session.Delete(orderline);
Well the same error appeared again. Then I tried following
order.Orderlines.Remove(orderline); session.SaveOrUpdate(order);
because of my cascading rule I thought that it would be fine to do so as the resulting operation would be to delete the orderline. however, with cascade set to “update-save”, NHibernate tried to set the OrderId null in Orderline table. which would fine (for those who wouldn’t mind orphan orderlines hanging around in the database table). But one of the constraints in the Orderline table is to make sure there is a OrderID (not null and foreign key). well, luckily there was a “cascade” property value to address this type of issue
cascade = “all-delete-orphan”.
To my surprise even changing cascade to “all-delete-orphan” didn’t resolved the original problem. Then, finally I started taking off my steel hat and started stepping through the code (which I should have done earlier) and the problem was at
order.Orderlines.Remove(orderline);
this command didn’t remove orderline from the collection and hence the association was there at the time of delete request/or saveupdate request.
Then I started looking other areas such as my equality comparer for entity. And that’s it. the problem was there.
Lesson: Make sure your equality comparer is robust enough. I changed mine to the code that was in Nhibernate cookbook 3.0 and that resolved it.
Note: once the equality comparer is fixed, both delete and SaveOrUpdate would result in removal of record from the database what is best way is dependent on your Domain, if Order is the aggregate root, use Removing from order and save order, if Orderline is aggregate root again remove orderline from order and delete the orderline.
We are building as system that will be deployed in Windows 2008 R2 platform with IIS 7 and Oracle 11g.
I had some trouble getting Oracle.DataAccess working in both Visual studio and Testing server. Visual studio is 32 and the development server that comes with it is 32 bit. I want to use 64bit ODP.NET not the 32 bit that comes with Oracle providers for NET.
If I install Oracle Providers for NET and run it in development machine it works fine as it will be using 32 bit Oracle.DataAccess. However as soon as I deploy in Testing Server. BadImangeFormat exception occurs.
It appears that Microsoft .NET driver for Oracle performs slow when there are a large number of records e.g. 30 mil (in my case). However, ODP.NET seems to handle it quite well. So in order to use ODP.NET as driver for NHibernate.
You need to specify driver class such as. (and obviously, it needs to be installed on the machine/web server)
NHibernate.Driver.OracleDataClientDriver
You also need to reference Oracle.DataAccess.dll into your project and set it to copy to bin folder.
Oracle10gDialect works for both 10g and 11g. You need to update
{servicename} with service name (database)
{username} with user
and {pass} with password
NHibernate.Connection.DriverConnectionProvider NHibernate.Dialect.Oracle10gDialect true 1, false 0, yes 'Y', no 'N' NHibernate.Driver.OracleClientDriver Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = {servicename})));User Id={username};Password={pass}; NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle true thread_static
Here, I am converting string array to List and then calling extension method ForEach. This may not be very efficient when performance is very critical component of your design.
I haven’t benchmarked the performance against simple loop though.
public static class MyExtensions
{
public static string ToComaSeparatedList(this string[] stringArray)
{
StringBuilder sb = new StringBuilder();
string output = string.Empty;
if (stringArray != null && stringArray.Length > 0)
{
stringArray.ToList().ForEach(x => { sb.Append(","); sb.Append(x); });
output = sb.ToString().Substring(1);
}
return output;
}
}
Public Function ChangeToNullableType _
(ByVal source As Type, ByVal value As Object, _
Optional ByVal culture As System.Globalization.CultureInfo = Nothing) As Object
If culture Is Nothing Then
culture = Globalization.CultureInfo.InvariantCulture
End If
Dim valueBaseType As Type = value.GetType()
Dim underlyingtype As Type = Nullable.GetUnderlyingType(source)
If underlyingtype IsNot Nothing Then
Dim tmp
If underlyingtype.Equals(valueBaseType) Then
tmp = value
Else
tmp = Convert.ChangeType(value, underlyingtype, culture)
End If
Dim obj = Activator.CreateInstance(source, New Object() {tmp})
Return obj
End If
Return value
End Function
 Â
_
   Public Function MakeNullable(ByVal basetype As Type) As Type
       Dim datatype As Type = basetype
       If basetype.IsValueType Then
           Dim genericType As Type = GetType(Nullable(Of ))
           Dim typeArgs() As Type = {basetype}
           datatype = genericType.MakeGenericType(typeArgs)
       End If
       Return datatype
   End Function