/// <summary> /// Does a cascade delete of an object for this property /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeDelete(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); Mapper.Manager MappingProvider = IoC.Manager.Bootstrapper.Resolve <Mapper.Manager>(); IMapping PropertyMapping = MappingProvider[typeof(DataType), Source]; IBatch Batch = Provider.Batch(Source); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) { return(Provider.Batch(Source)); } if (AspectObject != null) { ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); } DataType Item = CompiledExpression(Object); if (Item == null) { return(Batch); } foreach (IProperty <DataType> Property in PropertyMapping.Properties.Where(x => x.Cascade)) { Batch.AddCommand(Property.CascadeDelete(Item, Source, ObjectsSeen.ToList())); } Batch.AddCommand(Provider.Generate <DataType>(Source, PropertyMapping, Structure).Delete(Item)); Utilities.IoC.Manager.Bootstrapper.Resolve <DataTypes.Caching.Manager>().Cache().RemoveByTag(typeof(DataType).GetName()); return(Batch); }
/// <summary> /// Does a cascade save of an object for this property /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects that have been seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); if (Object == null || ObjectsSeen.Contains(GetValue(Object))) { return(Provider.Batch(Source)); } return(Provider.Generate <ClassType>(Source, Mapping).Save <DataType>(Object)); }
/// <summary> /// Sets up the specified database schema /// </summary> /// <param name="Mappings">The mappings.</param> /// <param name="Database">The database.</param> /// <param name="QueryProvider">The query provider.</param> public void Setup(ListMapping <IDatabase, IMapping> Mappings, IDatabase Database, QueryProvider.Manager QueryProvider) { ISourceInfo TempSource = SourceProvider.GetSource(Database.Name); var TempDatabase = new Schema.Default.Database.Database(Regex.Match(TempSource.Connection, "Initial Catalog=(.*?;)").Value.Replace("Initial Catalog=", "").Replace(";", "")); SetupTables(Mappings, Database, TempDatabase); SetupJoiningTables(Mappings, Database, TempDatabase); SetupAuditTables(Database, TempDatabase); foreach (ITable Table in TempDatabase.Tables) { Table.SetupForeignKeys(); } List <string> Commands = GenerateSchema(TempDatabase, SourceProvider.GetSource(Database.Name)).ToList(); IBatch Batch = QueryProvider.Batch(SourceProvider.GetSource(Database.Name)); for (int x = 0; x < Commands.Count; ++x) { if (Commands[x].ToUpperInvariant().Contains("CREATE DATABASE")) { QueryProvider.Batch(SourceProvider.GetSource(Regex.Replace(SourceProvider.GetSource(Database.Name).Connection, "Initial Catalog=(.*?;)", ""))).AddCommand(null, null, CommandType.Text, Commands[x]).Execute(); } else if (Commands[x].Contains("CREATE TRIGGER") || Commands[x].Contains("CREATE FUNCTION")) { if (Batch.CommandCount > 0) { Batch.Execute(); Batch = QueryProvider.Batch(SourceProvider.GetSource(Database.Name)); } Batch.AddCommand(null, null, CommandType.Text, Commands[x]); if (x < Commands.Count - 1) { Batch.Execute(); Batch = QueryProvider.Batch(SourceProvider.GetSource(Database.Name)); } } else { Batch.AddCommand(null, null, CommandType.Text, Commands[x]); } } Batch.Execute(); }
/// <summary> /// Called to create a batch that saves items from the joining tables /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeJoinsSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); Mapper.Manager MappingProvider = IoC.Manager.Bootstrapper.Resolve <Mapper.Manager>(); IMapping PropertyMapping = MappingProvider[typeof(DataType), Source]; IBatch Batch = Provider.Batch(Source); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) { return(Provider.Batch(Source)); } if (AspectObject != null) { ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); } IEnumerable <DataType> List = CompiledExpression(Object); if (List == null) { return(Batch); } foreach (DataType Item in List.Where(x => x != null)) { foreach (IProperty <DataType> Property in PropertyMapping.Properties) { if (!Property.Cascade && (Property is IMultiMapping || Property is ISingleMapping)) { Batch.AddCommand(Property.JoinsSave(Item, Source, ObjectsSeen.ToList())); } else if (Property.Cascade) { Batch.AddCommand(Property.CascadeJoinsSave(Item, Source, ObjectsSeen.ToList())); } } } Batch.AddCommand(Provider.Generate <ClassType>(Source, Mapping, Structure).JoinsSave <IEnumerable <DataType>, DataType>(this, Object)); return(Batch); }
/// <summary> /// Called to create a batch that saves items from the joining table /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch JoinsSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) { return(Provider.Batch(Source)); } if (AspectObject != null) { ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); } return(Provider.Generate <ClassType>(Source, Mapping, Structure).JoinsSave <ICollection <DataType>, DataType>(this, Object)); }
/// <summary> /// Called to create a batch that saves items from the joining table /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch JoinsSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); return(Provider.Batch(Source)); }