internal object LoadRelation(object parentObject) { var localFieldValue = LocalField.GetField(parentObject); var foreignRepository = ForeignSchema.Repository; if (IsToOne) { var serializedForeignObject = localFieldValue == null ? null : foreignRepository.DataProvider.ReadObject(new Dictionary <string, object> { { ForeignField.MappedName, localFieldValue } }, ForeignSchema); var relationObject = serializedForeignObject != null?Ir.WithLoadedRelations(ForeignSchema.UpdateObject(Activator.CreateInstance(FieldType), serializedForeignObject), ForeignSchema.DatasetRelations) : null; if (ReverseRelation != null) { relationObject = ReverseRelation.SetField(relationObject, parentObject); } return(relationObject); } if (RelationType == RelationType.OneToMany) { var parameter = Expression.Parameter(ElementType, "x"); Expression exp1 = Expression.MakeMemberAccess(parameter, ForeignField.FieldInfo); Expression exp2 = Expression.Constant(localFieldValue, LocalField.FieldType); if (exp2.Type != exp1.Type) { exp2 = Expression.Convert(exp2, exp1.Type); } var filter = new FilterSpec(Expression.Lambda(Expression.Equal(exp1, exp2), parameter)); if (IsDataSet) { return(Activator.CreateInstance(typeof(DataSet <>).MakeGenericType(ElementType), ForeignSchema.Repository, filter, this, parentObject)); } else { return(CreateCollection(foreignRepository.GetRelationObjects(foreignRepository.CreateQuerySpec(filter), this, parentObject))); } } return(null); }
internal QuerySpec CreateQuerySpec(FilterSpec filter, ScalarSpec scalarSpec = null, int?skip = null, int?take = null, SortOrderSpec sortSpec = null) { if (DataProvider.SupportsQueryTranslation()) { return(DataProvider.CreateQuerySpec(filter, scalarSpec, sortSpec, skip, take, Schema)); } var querySpec = new QuerySpec(new CodeQuerySpec(), null); var codeQuerySpec = (CodeQuerySpec)querySpec.Code; if (filter != null) { foreach (var expression in filter.Expressions) { codeQuerySpec.AddFilter(Schema, expression); } } if (sortSpec != null) { foreach (var expression in sortSpec.Expressions) { codeQuerySpec.AddSort(Schema, expression.Expression, expression.SortOrder); } } if (scalarSpec != null) { codeQuerySpec.AddScalar(Schema, scalarSpec.Expression); } codeQuerySpec.Skip = skip; codeQuerySpec.Take = take; return(querySpec); }
public QuerySpec CreateQuerySpec(FilterSpec filter, ScalarSpec expression, SortOrderSpec sortOrder, int?skip, int?take, TableSchema schema) { throw new NotSupportedException(); }