public static DatabaseQuery <T> WhereIn <T, K>(this DatabaseQuery <T> query, Expression <Func <T, object> > property, DatabaseQuery <K> subquery, Expression <Func <K, object> > targetProperty) where T : IEntity where K : IEntity { return((DatabaseQuery <T>)query.WhereIn(property.GetPropertyPath(), subquery, targetProperty.GetPropertyPath())); }
IEnumerable <IEntity> LoadTheAssociatedObjects(DatabaseQuery query) { var nestedQuery = Database.Of(Association.PropertyType); var provider = nestedQuery.Provider; return(nestedQuery .Where(provider.GetAssociationInclusionCriteria(query, Association)) .Include(IncludedNestedAssociations) .GetList()); }
internal override void Configure(DatabaseQuery query) { if (SqlCriteria.HasValue()) { query.Where(new DirectDatabaseCriterion(SqlCriteria)); } foreach (var item in Criterion.OrEmpty()) { query.Where(item); } }
public DatabaseQuery CloneFor(Type type) { var result = new DatabaseQuery(type) { PageStartIndex = PageStartIndex, TakeTop = TakeTop, PageSize = PageSize }; result.Criteria.AddRange(Criteria); result.include.Add(include); result.Parameters.Add(Parameters); return(result); }
DatabaseQuery WhereSubquery(string myField, DatabaseQuery subquery, string targetField, string @operator) { subquery.AliasPrefix = "Subq" + Guid.NewGuid().ToString().Remove("-").Substring(0, 6); var sql = subquery.Provider .GenerateSelectCommand(subquery, subquery.MapColumn(targetField)); sql = $"{MapColumn(myField)} {@operator} ({sql})"; Criteria.Add(Criterion.FromSql(sql)); foreach (var subQueryParam in subquery.Parameters) { Parameters.Add(subQueryParam.Key, subQueryParam.Value); } return(this); }
public void LoadAssociations(DatabaseQuery query, IEnumerable <IEntity> mainObjects) { if (mainObjects.None()) { return; } var associatedObjects = LoadTheAssociatedObjects(query); var groupedObjects = GroupTheMainObjects(mainObjects); var cachedField = query.EntityType.GetField("cached" + Association.Name, BindingFlags.NonPublic | BindingFlags.Instance); if (cachedField == null) { return; } foreach (var associatedObject in associatedObjects) { var group = groupedObjects.GetOrDefault(associatedObject.GetId()); if (group == null) { if (query.PageSize.HasValue) { continue; } throw new Exception("Database include binding failed.\n" + "The loaded associated " + associatedObject.GetType().Name + " with id " + associatedObject.GetId() + "\n" + "is not referenced by any " + Association.DeclaringType.Name + "object!\n\n" + "All associated " + Association.Name + " Ids are:\n" + groupedObjects.Select(x => x.Key).ToLinesString()); } foreach (var mainEntity in group) { BindToCachedField(cachedField, associatedObject, mainEntity); } } }
public static T WhereIn <T, K>(this T query, DatabaseQuery <K> subquery, Expression <Func <K, object> > targetProperty) where T : DatabaseQuery where K : IEntity => query.WhereIn(subquery, targetProperty.GetPropertyPath());
public static DatabaseQuery <T> WhereIn <T>(this DatabaseQuery <T> query, Expression <Func <T, object> > property, DatabaseQuery subquery, string targetField) where T : IEntity => (DatabaseQuery <T>)query.WhereIn(property.GetPropertyPath(), subquery, targetField);
public static T WhereIn <T>(this T query, DatabaseQuery subquery, string targetField) where T : DatabaseQuery => query.WhereIn <T>("ID", subquery, targetField);
public static T WhereIn <T>(this T query, string myField, DatabaseQuery subquery, string targetField) where T : DatabaseQuery => (T)query.WhereIn(myField, subquery, targetField);
internal abstract void Configure(DatabaseQuery query);
public DatabaseCriterionSqlGenerator(DatabaseQuery query) { Query = query; EntityType = query.EntityType; }
public SqlCriterionGenerator(DatabaseQuery query) : base(query) { }
internal override void Configure(DatabaseQuery query) => query.Page(StartIndex, PageSize);
DatabaseQuery WhereNotIn(string myField, DatabaseQuery subquery, string targetField) { return(WhereSubquery(myField, subquery, targetField, "NOT IN")); }