public void MergeProfiles(Profile targetProfile, RcfProfile rcfProfile, FideProfile fideProfile) { using (var db = new Ri2Context()) { targetProfile = db.Profiles.FirstOrDefault(x => x.Id == targetProfile.Id); if (targetProfile == null) { return; } if (rcfProfile != null) { rcfProfile = db.RcfProfiles.FirstOrDefault(x => x.Id == rcfProfile.Id); } if (fideProfile != null) { fideProfile = db.FideProfiles.FirstOrDefault(x => x.Id == fideProfile.Id); } if (rcfProfile != null) { targetProfile.RcfProfile = rcfProfile; } if (fideProfile != null) { targetProfile.FideProfile = fideProfile; if (rcfProfile != null) { rcfProfile.FideProfile = fideProfile; } } db.SaveChanges(); } }
private static void ProcessFide() { var query = SimpleXmlStream.SimpleStreamAxis(FideFilePath, FideXmlElements.Player); var add = new List <FideProfile>(100000); var mod = new List <FideProfile>(100000); Dictionary <int, int> t; using (var db = new Ri2Context { Configuration = { AutoDetectChangesEnabled = false } }) { t = db.FideProfiles.Select(x => new { x.FideId, x.Id }) .ToDictionary(o => o.FideId, o => o.Id); } foreach (var profile in query) { if (!Settings.Current.Filter.Contains(profile.Element(FideXmlElements.Country)?.Value)) { continue; } if (profile.Element(FideXmlElements.Name)?.Value == "") { continue; } var pr = new FideProfile { Name = (profile.Element(FideXmlElements.Name)?.Value == "" ? "_" : profile.Element(FideXmlElements.Name)?.Value) ?? "_", FideId = Convert.ToInt32((profile.Element(FideXmlElements.FideId)?.Value == "" ? "0" : profile.Element(FideXmlElements.FideId)?.Value) ?? "0"), Std = Convert.ToInt32((profile.Element(FideXmlElements.Std)?.Value == "" ? "0" : profile.Element(FideXmlElements.Std)?.Value) ?? "0"), Rpd = Convert.ToInt32((profile.Element(FideXmlElements.Rpd)?.Value == "" ? "0" : profile.Element(FideXmlElements.Rpd)?.Value) ?? "0"), Blz = Convert.ToInt32((profile.Element(FideXmlElements.Blz)?.Value == "" ? "0" : profile.Element(FideXmlElements.Blz)?.Value) ?? "0"), Birth = Convert.ToInt32((profile.Element(FideXmlElements.Birth)?.Value == "" ? "0" : profile.Element(FideXmlElements.Birth)?.Value) ?? "0") }; if (pr.Birth < Settings.Current.BirthCutoff) { continue; } //File.AppendAllText("log.txt",pr.FideId+Environment.NewLine); //using (var ri2 = new Ri2Context {Configuration = {AutoDetectChangesEnabled = false}}) { //var t = ri2.FideProfiles.FirstOrDefault(cp => cp.FideId == pr.FideId); //if (t != null) if (t.ContainsKey(pr.FideId)) { //pr.Id = t.Id; pr.Id = t[pr.FideId]; mod.Add(pr); } else { add.Add(pr); } } } using (var db = new Ri2Context()) { EFBatchOperation.For(db, db.FideProfiles).InsertAll(add); db.SaveChanges(); } using (var db = new Ri2Context()) { EFBatchOperation.For(db, db.FideProfiles).UpdateAll(mod, x => x.ColumnsToUpdate(c => c.Name, c => c.Birth, c => c.Std, c => c.Rpd, c => c.Blz)); db.SaveChanges(); } }