/// <summary> /// Loads a property (primarily used internally for lazy loading) /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <typeparam name="TData">The type of the data.</typeparam> /// <param name="objectToLoadProperty">The object to load property.</param> /// <param name="propertyName">Name of the property.</param> /// <returns>The appropriate property value</returns> public IList <TData> LoadProperties <TObject, TData>(TObject objectToLoadProperty, string propertyName) where TObject : class where TData : class { var Results = new List <QueryResults>(); foreach (var Source in MappingManager.ReadSources.Where(x => x.Mappings.ContainsKey(typeof(TObject))) .OrderBy(x => x.Order)) { var Batch = QueryProviderManager.CreateBatch(Source.Source, DynamoFactory); var Generator = QueryProviderManager.CreateGenerator <TObject>(Source); var Property = FindProperty <TObject, TData>(Source, propertyName); var Queries = Generator.GenerateQueries(QueryType.LoadProperty, objectToLoadProperty, Property); for (int x = 0, QueriesLength = Queries.Length; x < QueriesLength; x++) { var TempQuery = Queries[x]; Batch.AddQuery(TempQuery.DatabaseCommandType, TempQuery.QueryString, TempQuery.Parameters !); } List <List <dynamic> >?ResultLists = null; try { ResultLists = Task.Run(async() => await Batch.ExecuteAsync().ConfigureAwait(false)).GetAwaiter().GetResult(); } catch { Logger.Debug("Failed on query: " + Batch.ToString()); throw; } for (int x = 0, ResultListsCount = ResultLists.Count; x < ResultListsCount; ++x) { if (x >= Queries.Length) { continue; } var IDProperties = Source.GetParentMapping(Queries[x].ReturnType).SelectMany(y => y.IDProperties); var TempQuery = new QueryResults(Queries[x], ResultLists[x].Cast <Dynamo>(), this); var Result = Results.Find(y => y.CanCopy(TempQuery, IDProperties)); if (Result != null) { Result.CopyOrAdd(TempQuery, IDProperties); } else { Results.Add(TempQuery); } } } return(Results.SelectMany(x => x.ConvertValues <TData>()).ToObservableList(x => x)); }
/// <summary> /// Deletes the joins if it needs to. /// </summary> /// <param name="object">The object.</param> /// <param name="source">The source.</param> /// <param name="batch">The batch.</param> /// <param name="ManyToManyProperty">The many to many property.</param> /// <param name="ManyToManyValueList">The many to many value list.</param> private void DeleteJoins(object @object, IMappingSource source, SQLHelper batch, IManyToManyProperty ManyToManyProperty, IList ManyToManyValueList) { if (ManyToManyProperty.DatabaseJoinsCascade) { return; } ManyToManyValueList.Clear(); var LinksGenerator = QueryProviderManager.CreateGenerator(ManyToManyProperty.ParentMapping.ObjectType, source); var TempQueries = LinksGenerator.GenerateQueries(QueryType.JoinsDelete, @object, ManyToManyProperty); for (int x = 0, TempQueriesLength = TempQueries.Length; x < TempQueriesLength; ++x) { var TempQuery = TempQueries[x]; batch.AddQuery(TempQuery.DatabaseCommandType, TempQuery.QueryString, TempQuery.Parameters !); } }
public void CreateGenerator() { var Mappings = new MappingSource(new IMapping[] { new BaseClass1Mapping(), new ConcreteClass1Mapping(), new ConcreteClass2Mapping(), new ConcreteClass3Mapping(), new IInterface1Mapping(), new IInterface2Mapping() }, new MockDatabaseMapping(), new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger), Canister.Builder.Bootstrapper.Resolve <ILogger>(), ObjectPool); var TempQueryProvider = new SQLServerQueryProvider(Configuration, ObjectPool); var TestObject = new QueryProviderManager(new[] { TempQueryProvider }, Logger); var Result = TestObject.CreateGenerator <ConcreteClass1>(Mappings); Assert.NotNull(Result); Assert.Equal(typeof(ConcreteClass1), Result.AssociatedType); }
/// <summary> /// Deletes the specified object. /// </summary> /// <param name="object">The object.</param> /// <param name="source">The source.</param> /// <param name="batch">The batch.</param> /// <param name="objectsSeen">The objects seen.</param> private void Delete(object? @object, IMappingSource source, SQLHelper batch, IList <object> objectsSeen) { if (@object is null || WasObjectSeen(@object, objectsSeen, source) || !CanExecute(@object, source)) { return; } objectsSeen.Add(@object); DeleteCascade(@object, source, batch, objectsSeen); var Generator = QueryProviderManager.CreateGenerator(@object.GetType(), source); var Queries = Generator.GenerateQueries(QueryType.Delete, @object); for (int x = 0, QueriesLength = Queries.Length; x < QueriesLength; x++) { var TempQuery = Queries[x]; batch.AddQuery(TempQuery.DatabaseCommandType, TempQuery.QueryString, TempQuery.Parameters !); } RemoveItemsFromCache(@object); }