Beispiel #1
0
        /// <summary>
        /// (Read)Fills the 'one' side of OTM relations for each request
        /// </summary>
        public bool FillOTM()
        {
            bool result = false;

            while (OTMReqList.Count() > 0)
            {
                result = true;
                Tuple <object, PropertyInfo> request = OTMReqList[0];
                int      id         = (int)request.Item1.GetType().GetProperty("id").GetValue(request.Item1);
                String   otm_target = CustomAttr.GetOTMTarget(request.Item2);
                List <T> filtered   = new List <T>();
                foreach (T record in allRecords)
                {
                    BaseClass target = (BaseClass)record.GetType().GetProperty(otm_target).GetValue(record);
                    if (target == null)
                    {
                        continue;
                    }
                    if (target.id == id)
                    {
                        IList list = request.Item1.GetType().GetProperty(request.Item2.Name).GetValue(request.Item1) as IList;
                        list.Add(record);
                    }
                }
                OTMReqList.RemoveAt(0);
            }
            return(result);
        }
Beispiel #2
0
        public BaseClass()
        {
            String name = this.GetType().Name;

            if (!InheritedTypes.ContainsKey(name))
            {
                InheritedTypes.Add(name, this.GetType());

                AllPrimitiveInfos.Add(name, new List <PropertyInfo>());
                AllOTORelInfos.Add(name, new List <PropertyInfo>());
                AllOTM_One.Add(name, new List <PropertyInfo>());
                AllOrderedInfos.Add(name, new List <PropertyInfo>());
                AllMTMInfoList.Add(name, new List <MTMRelationInfo>());

                List <PropertyInfo> infos = this.GetType().GetProperties().ToList();
                foreach (PropertyInfo info in infos)
                {
                    if (info.PropertyType.IsSubclassOf(typeof(BaseClass)))
                    {
                        AllOTORelInfos[name].Add(info);
                        AllOrderedInfos[name].Add(info);
                    }
                    else if (info.PropertyType.IsGenericType)
                    {
                        if (CustomAttr.GetOTMTarget(info) != null)
                        {
                            AllOTM_One[name].Add(info);
                        }
                        else
                        {
                            Tuple <string, string> Target_Table = CustomAttr.GetMTMTargetAndTable(info);
                            if (Target_Table != null)
                            {
                                Type         targetType = info.PropertyType.GetGenericArguments()[0];
                                PropertyInfo targetInfo = info.PropertyType.GetGenericArguments()[0].GetProperty(Target_Table.Item1);

                                if (!AllMTMRelations.Any(e => e.Key == Target_Table.Item2)) //tablo adına göre kontrol ediyor
                                {
                                    AllMTMRelations.Add(
                                        Target_Table.Item2, new Tuple <Type, Type>(this.GetType(), targetType)
                                        );
                                }
                                AllMTMInfoList[name].Add(new MTMRelationInfo(Target_Table.Item2, info));
                            }
                        }
                    }
                    else
                    {
                        AllPrimitiveInfos[name].Add(info);
                        AllOrderedInfos[name].Add(info);
                    }
                }
                RowSizes.Add(name, FileOps.CalculateRowByteSize(OrderedInfos(), OTORelInfos(), PrimitiveInfos()));
            }
        }
Beispiel #3
0
 /// <summary>
 /// Checks inside the given record for OTO-OTM-MTM relations and processes them by sending to the corresponding dbset methods.
 /// </summary>
 /// <param name="record"></param>
 /// <param name="mode"></param>
 public void CheckInside(BaseClass record, String mode)
 {
     foreach (PropertyInfo info in record.GetType().GetProperties())
     {
         if (ctx.dbsetTypes.Any(t => t.Name == info.PropertyType.Name))
         {
             BaseClass childObject = (BaseClass)info.GetValue(record);
             if (childObject != null)
             {
                 if (childObject.id == 0)
                 {
                     object   dbset      = ctx.GetDBSetByType(childObject.GetType());
                     object[] parameters = { record, childObject };
                     dbset.GetType().GetMethod("AddAsChild").Invoke(dbset, parameters);
                 }
             }
         }
     }
     //one to many
     foreach (PropertyInfo OTM in record.OTM_One())
     {
         IList  list  = OTM.GetValue(record) as IList;
         object dbset = ctx.GetDBSetByType(OTM.PropertyType.GetGenericArguments()[0]);
         foreach (BaseClass eleman in list)
         {
             if (eleman.id != 0)
             {
                 PropertyInfo targetProp = eleman.GetType().GetProperty(CustomAttr.GetOTMTarget(OTM));
                 //bizde liste var, karşıda ise tek nesneye referans
                 if (targetProp.GetValue(eleman) != record)
                 {
                     targetProp.SetValue(eleman, record);
                     object[] parameters_update = { eleman };
                     object   updates           = dbset.GetType().GetField("Updates").GetValue(dbset); //içindeki tekrar eklenmesin diye Update fonksiyonunu pas geçtim.
                     updates.GetType().GetMethod("Add").Invoke(updates, parameters_update);
                 }
                 continue;
             }
             object[] parameters = new object[3];
             parameters[0] = record;
             parameters[1] = eleman;
             parameters[2] = eleman.GetType().GetProperty(CustomAttr.GetOTMTarget(OTM));
             dbset.GetType().GetMethod("AddAsOTM").Invoke(dbset, parameters);
         }
     }
 }