Esempio n. 1
0
        public void TestIfMultikeysCanBeConverted()
        {
            var guid       = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
            var guidString = guid.ToString().Replace("-", "");
            IPersistenceCapable orderDetail = pm.FindObject(typeof(OrderDetail), new object[] { guid, guid });
            string shortId = ((IPersistenceCapable)orderDetail).ShortId();

            Assert.That(shortId.IsShortId());
            Assert.That(shortId.GetEntityName() == "OrderDetail");
            Assert.That(shortId.GetObjectType(pm) == typeof(OrderDetail));
            string[] arr = shortId.Split('-');
            Assert.AreEqual($"{guidString}+{guidString}", arr[2]);
            var decodedShortId = shortId.Decode();

            arr = decodedShortId.Split('-');
            Assert.AreEqual($"{guidString} {guidString}", arr[2]);

#if !USEGUIDS
            orderDetail = pm.FindObject(typeof(OrderDetail), new object[] { 1, 2 });
            shortId     = orderDetail.ShortId();
#endif
            orderDetail = pm.FindObject(shortId);
#if USEGUIDS
            Assert.AreEqual(guid, orderDetail.NDOObjectId.Id.Values[0]);
            Assert.AreEqual(guid, orderDetail.NDOObjectId.Id.Values[1]);
#else
            Assert.AreEqual(1, orderDetail.NDOObjectId.Id.Values[0]);
            Assert.AreEqual(2, orderDetail.NDOObjectId.Id.Values[1]);
#endif
        }
Esempio n. 2
0
        public static IDictionary <string, object> ToDictionary(this IPersistenceCapable pc, IPersistenceManager pm)
        {
            if (pc == null)
            {
                return(new Dictionary <string, object>());
            }

            if (pm == null)
            {
                var sm = pc.NDOStateManager;
                if (sm == null)
                {
                    throw new Exception("ToDictionary: pm == null und kann nicht aus dem Objekt ermittelt werden.");
                }
                pm = sm.PersistenceManager;
            }

            Type     myType = pc.GetType();
            FieldMap fm     = new FieldMap(myType);
            Dictionary <string, object> result = new Dictionary <string, object>();

            foreach (var dictEntry in fm.PersistentFields)
            {
                MemberInfo mi = (MemberInfo)dictEntry.Value;
                if (!(mi is FieldInfo))
                {
                    continue;                      // This are properties of embedded value types or classes. We should extend the code here, to support embedded members.
                }
                FieldInfo fi = (FieldInfo)dictEntry.Value;

                object obj = fi.GetValue(pc);
                result.Add(dictEntry.Key, obj);
            }

            result.Add("_oid", pc.ShortId());
            result.Add("NDOObjectState", pc.NDOObjectState);
            return(result);
        }