ServerMapping is causing AmbiguousMatchException with NHibernate proxied classes
New Community Forums available at http://forums.ext.net
 

Coolite Forums

Welcome Guest ( Login | Register )
 
ServerMapping is causing...
Subscribe
Last Login: 6/21/2010 11:30:44 AM
Posts: 17,
Posted 1/28/2010 2:26:00 PM

Group: Coolite Early Adopter

I'm getting AmbiguousMatchException when I try to use the ServerMapping setting in a RecordField of a Store.

I've found that this error is thrown in the method: Coolite.Ext.Web.StoreDataBound.GetFieldValue(), because is trying to get the value of a property that is defined in a proxied class (the class was proxied by NHibernate).

In my case, the original class was: TimeKeeping.Common.Group, but NHibernate is proxying it as CProxyTypeTimeKeeping_Common_TablesGroupTables_NHibernate_ProxyINHibernateProxy1 because its first cache level. All the defined properties in the first class are redefined in the second class. That's why the Ambiguous Exception is thrown.

If I try to use IsComplex instead of the ServerMapping property, I'm getting a different error, but i'm sure that is caused by something connected with this.

Regards,
Ariel

Last Login: 6/1/2010 11:48:53 PM
Posts: 9,
Posted 2/11/2010 10:15:53 AM

Group: Coolite Early Adopter
 hi!
i have the same error!
use nhibernate + castle record
and when populate store is error happen!
{"Ambiguous match found."}
who solve this problem ? how ?

Last Login: 6/21/2010 11:30:44 AM
Posts: 17,
Posted 2/11/2010 10:30:43 AM

Group: Coolite Early Adopter
Hello,

I made a little change to the Coolite code, when the property is retrieved, in order to detect if the object that is inspected is an NHibernate Proxy or not.

Regards,
Ariel
Last Login: 6/1/2010 11:48:53 PM
Posts: 9,
Posted 2/11/2010 12:19:25 PM

Group: Coolite Early Adopter
 cant share u code ?

Last Login: 6/21/2010 11:30:44 AM
Posts: 17,
Posted 2/11/2010 12:51:55 PM

Group: Coolite Early Adopter

These are the steps you must follow:

1) Open coolite sourcecode
2) Add a reference to NHibernate dll
3) Edit StoreDataBound.cs in Coolite.Ext.Web\Ext\Data
4) Replace the function named GetFieldValue with this one


        private object GetFieldValue(AutoGeneratedFieldProperties property, object obj, RecordField field)
        {
            if (field!= null && !string.IsNullOrEmpty(field.ServerMapping))
            {
                string[] mapping = field.ServerMapping.Split('.');
                if (mapping.Length > 1)
                {
                    for (int i = 0; i < mapping.Length; i++)
                    {
                        PropertyInfo p = null;


                        if (obj is NHibernate.Proxy.INHibernateProxy)
                            p = obj.GetType().BaseType.GetProperty(mapping[i]);
                        else
                            p = obj.GetType().GetProperty(mapping[i]);


                        obj = p.GetValue(obj, null);
                        if (obj == null)
                        {
                            return null;
                        }
                    }


                    return obj;
                }
            }


            return DataBinder.GetPropertyValue(obj, property.DataField);
        }



5) Compile  the Coolite Dll
6) Replace your current reference to this new Dll and add the NHibernate Dll.

Ariel

« Prev Topic | Next Topic »
Reading This Topic
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.
All times are GMT -5:00, Time now is 8:34pm