public override object Instantiate(string clazz, EntityMode entityMode, object id)
        {
            if (entityMode == EntityMode.Poco)
            {
                Type type = FindByType(clazz);
                if (type != null)
                {
                    var instance = DataBindingFactory.Create(type);
                    SessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode);
                    return(instance);
                }
            }

            return(base.Instantiate(clazz, entityMode, id));
        }
Esempio n. 2
0
            /// <summary>
            /// Returns an entity from the persistence store, or a new entity
            /// </summary>
            /// <param name="type"></param>
            /// <param name="id">String representation of the id</param>
            /// <returns></returns>
            protected override object GetInstance(string id)
            {
                object   result     = null;
                Type     objectType = Type.GetType(this.QualifiedName);
                ISession session    = sessionFactory.GetCurrentSession();

                if (string.IsNullOrEmpty(id))
                {
                    result = DataBindingFactory.Create(objectType);
                }
                else
                {
                    IClassMetadata metadata = sessionFactory.GetClassMetadata(objectType);
                    object         idObject = TypeDescriptor.GetConverter(metadata.IdentifierType.ReturnedClass).ConvertFromString(id);
                    result = session.Load(objectType, idObject);
                }

                return(result);
            }
Esempio n. 3
0
        public override INHibernateProxy GetProxy(object id, global::NHibernate.Engine.ISessionImplementor session)
        {
            try
            {
                var initializer = new LazyInitializer(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod, ComponentIdType, session);

                object generatedProxy = IsClassProxy
                                                                                        ? DataBindingFactory.Create(PersistentClass, Interfaces, initializer)
                                                                                        : ProxyGenerator.CreateInterfaceProxyWithoutTarget(Interfaces[0], Interfaces,
                                                                                                                                           initializer);

                initializer._constructed = true;
                return((INHibernateProxy)generatedProxy);
            }
            catch (Exception e)
            {
                throw new HibernateException("Creating a proxy instance failed", e);
            }
        }