/// <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); } } }
public void ReadAll(bool ReadRemoved = false) { allRecords = new List <T>(); OpenMainRead(); BaseClass trash = (BaseClass)Activator.CreateInstance(typeof(T)); int line = Convert.ToInt32(mainFile.Length) / trash.RowSize(); for (int id = 0; id < line; id++) { Tuple <BaseClass, Dictionary <PropertyInfo, int> > fillingLog; fillingLog = FileOps.ReadSingleRecord(mainFile, id + 1, typeof(T)); BaseClass rec = fillingLog.Item1; if (ReadRemoved || !rec.removed) { allRecords.Add((T)rec); foreach (KeyValuePair <PropertyInfo, int> kp in fillingLog.Item2) //OTOReq'ler { object dbset = ctx.GetDBSetByType(kp.Key.PropertyType); if (kp.Value == -1) //null, okumaya çalışma! { continue; } Tuple <object, PropertyInfo, int> RecordToBeFilled = new Tuple <object, PropertyInfo, int>(fillingLog.Item1, kp.Key, kp.Value); object[] parameters = { new OTOReq(fillingLog.Item1, kp.Key, kp.Value) }; dbset.GetType().GetMethod("AddOTOReq").Invoke(dbset, parameters); } foreach (PropertyInfo OTM in trash.OTM_One()) { if (OTM.GetValue(fillingLog.Item1) == null) { OTM.SetValue(OTM.GetValue(fillingLog.Item1), Activator.CreateInstance(OTM.PropertyType)); } object dbset = ctx.GetDBSetByType(OTM.PropertyType.GetGenericArguments()[0]); object[] parameters = { new Tuple <object, PropertyInfo>(fillingLog.Item1, OTM) }; dbset.GetType().GetMethod("AddOTMReq").Invoke(dbset, parameters); } //MTM ReadMTM(fillingLog.Item1); } } mainFile.Close(); }