예제 #1
0
파일: DbSet.cs 프로젝트: denizcetiner/DKDB
 /// <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);
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Sets the removeFlag of the record to true in the file.
 /// </summary>
 /// <param name="mainFile">File stream of the dbset of the record.</param>
 /// <param name="customInfos"></param>
 /// <param name="primitiveInfos"></param>
 /// <param name="orderedInfos"></param>
 /// <param name="metaFile">MetaFile stream of the dbset. To update the removed indexes. (Burada mı yapılacak? düşün.)</param>
 /// <param name="record"></param>
 public static void Remove(Stream mainFile, Stream metaFile, BaseClass record)
 {
     record.GetType().GetProperty("removed").SetValue(record, true);
     Overwrite(mainFile, record);
     //removed indexes ile ilgili iş nerede yapılacak?
 }