private ForeignKeyRelationship CreateForeignKeyRelationship(NavigationProperty navigationProperty)
        {
            var relationship = new ForeignKeyRelationship()
            {
                Source = navigationProperty,
                Target = this.GetOtherNavigationProperty(navigationProperty),
            };

            return(relationship);
        }
        private MappingRelationshipForeignKeyView CreateView(ForeignKeyRelationship relationship)
        {
            var view = new MappingRelationshipForeignKeyView
            {
                EntityNecessity = this.GetEntityNecessity(relationship.Source),
                EntityName      = this.GetEntityName(relationship.Source),
                Attributes      = this.CreateAttributes(relationship).ToList(),
            };

            return(view);
        }
        //Rethinked, C. (2018) Building dynamic LINQ queries using Expression Trees and Func. Retrieved from https://coderethinked.com/building-dynamic-linq-queries-using-expression-trees-and-func/
        public async Task <List <Project> > GetRelatedItemsAsync <U>(U filterItem)
            where U : ISQLiteDataItem
        {
            ForeignKeyRelationship fkRelationship = SQLFactory.ForeignKeyRelationships.FirstOrDefault(x => x.PrimaryTable == filterItem.GetType());

            if (fkRelationship != null && fkRelationship.ForeignTable == typeof(Project))
            {
                Task <List <Project> > allItemsTask = GetAllItemsAsync();
                ParameterExpression    param        = Expression.Parameter(typeof(Project), name: "x");
                MemberExpression       member       = Expression.Property(param, typeof(Project).GetProperty(fkRelationship.ForeignKeyColumnName));
                ConstantExpression     constant     = Expression.Constant(filterItem.Id, typeof(int));
                Expression             body         = Expression.Equal(member, constant);
                Type delegateType             = typeof(Func <,>).MakeGenericType(typeof(Project), typeof(bool));
                Func <Project, bool> exp      = Expression.Lambda <Func <Project, bool> >(body, param).Compile();
                List <Project>       allItems = await allItemsTask.ConfigureAwait(false);

                return(allItems.Where(exp).ToList());
            }
            return(null);
        }
        private IEnumerable <string> CreateAttributes(ForeignKeyRelationship relationship)
        {
            var withManyMatcher = new MappingRelationshipForeignKeyMatcherWithMany(this.codeGenEscaper);
            var isWithManyMatch = withManyMatcher.IsMatch(relationship.Source);

            if (isWithManyMatch)
            {
                yield return($".WithMany(x => x.{withManyMatcher.GetEntityName(relationship.Target)})");
            }

            var hasForeignKeyMatcher = new MappingRelationshipForeignKeyMatcherHasForeignKey();

            if (isWithManyMatch && hasForeignKeyMatcher.IsMatch(relationship.Source))
            {
                yield return($".HasForeignKey({hasForeignKeyMatcher.FormattedKeys(relationship.Source)})");
            }

            var withOptionalMatcher = new MappingRelationshipForeignKeyMatcherWithOptional(this.codeGenEscaper);

            if (withOptionalMatcher.IsMatch(relationship.Source))
            {
                yield return($".WithOptional(x => x.{withOptionalMatcher.GetEntityName(relationship.Target)})");
            }
        }