diff options
| author | Roy <roy.mail.net@gmail.com> | 2018-01-27 17:18:10 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2018-01-27 17:18:10 +0200 |
| commit | 20482140c124fd1d5caaffcc9b0dfe853b30dd6f (patch) | |
| tree | 90ddae2089b030833cac9f008767d2b8f96c577f /Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI | |
| parent | 7426c54072d63e49eae8a8a9b9a1097c9ecefbd2 (diff) | |
| download | Tango-20482140c124fd1d5caaffcc9b0dfe853b30dd6f.tar.gz Tango-20482140c124fd1d5caaffcc9b0dfe853b30dd6f.zip | |
Re-factored DAL Observables using EF Code First !!!!!!
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI')
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs b/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs index 33f2d81ff..af0e1a08d 100644 --- a/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs +++ b/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs @@ -35,6 +35,8 @@ namespace Tango.DBObservablesGenerator.CLI TableName = table.Name, }; + List<String> foreignKeys = table.PropertyType.GenericTypeArguments.First().GetProperties().Skip(3).Where(x => x.PropertyType == typeof(String)).Where(x => x.Name.ToLower().Contains("guid")).Select(x => ObservableEntity.DalNameToStandardName(x.Name).SingularizeMVC().Replace("Guid", "")).ToList(); + foreach (var field in table.PropertyType.GenericTypeArguments.First().GetProperties().Skip(3)) { EntityCodeFileField codeField = new EntityCodeFileField(); @@ -50,13 +52,29 @@ namespace Tango.DBObservablesGenerator.CLI } else { - if (field.PropertyType.IsClass && field.PropertyType != typeof(String)) + if (field.PropertyType.IsClass && field.PropertyType != typeof(String) && field.PropertyType != typeof(byte[])) { codeField.Type = ObservableEntity.DalNameToStandardName(field.PropertyType.Name).SingularizeMVC(); + codeField.Name = codeField.Type; + + var fk = foreignKeys.SingleOrDefault(x => x.Contains(codeField.Name)); + + if (fk != null) + { + codeField.Name = fk; + } + + codeField.Complex = true; } else { codeField.Type = field.PropertyType.Name; + + if (codeField.Name.EndsWith("Guid")) + { + codeField.IsForeignKey = true; + codeField.ForeignKeyName = codeField.Name.Replace("Guid",""); + } } } codeFile.Fields.Add(codeField); @@ -131,6 +149,22 @@ namespace Tango.DBObservablesGenerator.CLI String adapterCode = adapterFile.GenerateCode(); File.WriteAllText(Path.Combine(targetPath, "ObservablesEntitiesAdapterExtension.cs"), adapterCode); //Generate Observables Adapter Extensions... + + //Generate Observables Context + ObservablesContextCodeFile contextFile = new ObservablesContextCodeFile(); + contextFile.Name = "ObservablesContext"; + + foreach (var table in typeof(RemoteDB).GetProperties().Where(x => typeof(IEnumerable).IsAssignableFrom(x.PropertyType))) + { + contextFile.Properties.Add(new Property() + { + Name = ObservableEntity.DalNameToStandardName(table.Name), + Type = String.Format("DbSet<{0}>", ObservableEntity.DalNameToStandardName(table.PropertyType.GenericTypeArguments.Single().Name).SingularizeMVC()), + }); + } + String contextCode = contextFile.GenerateCode(); + File.WriteAllText(Path.Combine(targetPath, "ObservablesContext.cs"), contextCode); + //Generate Observables Context } /// <summary> |
