예제 #1
0
        public Parent Copy()
        {
            Parent Copy = null;

            using (ISession Session = m_SessionFactory.OpenSession())
            {
                this.EvictProperties((Parent)base.m_ObjectFlow);
                Session.Evict(base.m_ObjectFlow);
                ((Parent)base.m_ObjectFlow).ID = HelperNHibernate.GenerateID();
                Copy = (Parent)Session.Merge(base.m_ObjectFlow);
            }
            return(Copy);
        }
예제 #2
0
        public static Object ToObject(String StrXML, String Ensamblado)
        {
            XmlDocument XML = new XmlDocument();

            XML.LoadXml(StrXML);

            Object   Objeto   = null;
            Type     Type     = null;
            Assembly Assembly = null;

            Assembly = Assembly.Load(Ensamblado);
            Type     = Assembly.GetType(String.Format("{0}.{1}", Ensamblado, XML.DocumentElement.Name));
            Objeto   = Activator.CreateInstance(Type);

            foreach (XmlAttribute Attr in XML.DocumentElement.Attributes)
            {
                if (!Attr.Name.Contains("Ref-"))
                {
                    PropertyInfo Prop = Objeto.GetType().GetProperty(Attr.Name);
                    Prop.SetValue(Objeto, GetValue(Prop.PropertyType, Attr.Value), null);
                }
                else
                {
                    String       Name    = Attr.Name.Replace("Ref-", "");
                    String[]     Strings = Name.Split('-');
                    PropertyInfo Prop    = Objeto.GetType().GetProperty(Strings[1]);
                    Prop.SetValue(Objeto, HelperNHibernate.GetEntityByID(Strings[0], Attr.Value), null);
                }
            }

            foreach (XmlNode Node in XML.DocumentElement.ChildNodes)
            {
                PropertyInfo Prop = Objeto.GetType().GetProperty(Node.Name);
                IList        List = (IList)Prop.GetValue(Objeto, null);
                foreach (XmlNode Item in Node.ChildNodes)
                {
                    Object ItemObj = ToObject(Item.OuterXml, Ensamblado);
                    List.Add(ItemObj);
                }
            }

            return(Objeto);
        }
예제 #3
0
 public void EvictProperties(Parent Entity)
 {
     using (ISession Session = m_SessionFactory.OpenSession())
     {
         Type           EntityType = Entity.GetType();
         PropertyInfo[] properties = EntityType.GetProperties();
         foreach (PropertyInfo Property in properties)
         {
             if (Property.PropertyType.Name.Equals("IList`1"))
             {
                 IList List = (IList)Property.GetValue(Entity, null);
                 foreach (Parent Item in List)
                 {
                     this.EvictProperties(Item);
                     Session.Evict(Item);
                     ((Parent)Item).ID = HelperNHibernate.GenerateID();
                 }
             }
         }
     }
 }