protected internal IEnumerable <object> GetRelationObjects(QuerySpec filter, TableSchema.Relation parentRelation, object parentObject) { var relations = Schema.BuildPreloadRelationSet(); var objects = from o in DataProvider.GetObjects(filter.Native, Schema) select Ir.WithLoadedRelations(Schema.UpdateObject(Activator.CreateInstance(Schema.ObjectType), o), relations); if (parentRelation?.ReverseRelation != null) { objects = from o in objects select parentRelation.ReverseRelation.SetField(o, parentObject); } if (filter.Code != null) { objects = from o in objects where filter.Code.IsFilterMatch(o) select o; } objects = objects.Select(o => { Fire_ObjectRead(o); return(o); }); return(objects); }
public virtual TableSchema.Field GetRelationField(TableSchema.Relation relation) { //if (relation.LocalSchema.PrimaryKeys.Length < 1 || relation.ForeignSchema.PrimaryKeys.Length < 1) // return null; string relationKeyName = (relation.IsToOne ? ManyToOneLocalKeyName : OneToManyForeignKeyName) .Replace(RELATION_CLASS_PRIMARYKEY, relation.ForeignSchema.PrimaryKeys.Length > 0 ? relation.ForeignSchema.PrimaryKeys[0].FieldName : "?") .Replace(RELATION_CLASS_NAME, relation.ForeignSchema.ObjectType.Name) .Replace(CLASS_PRIMARYKEY, relation.LocalSchema.PrimaryKeys.Length > 0 ? relation.LocalSchema.PrimaryKeys[0].FieldName : "?") .Replace(CLASS_NAME, relation.LocalSchema.ObjectType.Name); return(relation.IsToOne ? relation.LocalSchema.FieldsByFieldName[relationKeyName] : relation.ForeignSchema.FieldsByFieldName[relationKeyName]); }
private static LambdaExpression CreateToManyFilterExpression(TableSchema.Relation relation, Expression localExpression, LambdaExpression filterLambda, ParameterExpression lambdaParameter) { Expression exp1 = Expression.MakeMemberAccess(localExpression, relation.LocalField.FieldInfo); Expression exp2 = Expression.MakeMemberAccess(lambdaParameter, relation.ForeignField.FieldInfo); if (exp2.Type != exp1.Type) { exp2 = Expression.Convert(exp2, exp1.Type); } var expression = Expression.Equal(exp1, exp2); if (filterLambda != null) { expression = Expression.AndAlso(filterLambda.Body, expression); } return(Expression.Lambda(expression, lambdaParameter)); }