blob: affff76b03896f604c25be66161f60fc7a42ed50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
namespace Tango.CctOptimizer.CLI
{
class Program
{
static void Main(string[] args)
{
using (ObservablesContext db = ObservablesContext.CreateDefault())
{
var notUsedCcts = db.Ccts.Where(x => x.Rmls.All(y=>y.Cct.FileName != x.FileName)).ToObservableCollection();
foreach ( var cct in notUsedCcts)
{
cct.DeleteCascadeAsync(db);
}
Dictionary <string, List<Cct>> duplicates = db.Ccts.Where(x => x.Rmls.All(y => y.Cct.FileName == x.FileName)).GroupBy(x => x.FileName).Where(x => x.Count() > 1).ToDictionary(g=>g.Key, g => g.ToList());
foreach (var value in duplicates.Values)
{
var res = db.Rmls.Where(x => value.All(y => y.Guid == x.CctGuid )).ToList();
var cctsNotUsedInRML = value.Where(x => res.All(y => y.CctGuid != x.Guid)).ToList();
foreach (var cct in cctsNotUsedInRML)
{
cct.DeleteCascadeAsync(db);
}
}
db.SaveChanges();
}
}
}
}
|