private IEdmEntitySet GetEntitySet(GraphQLFieldSelection selection) { var listGraphType = (ListGraphType)_schema.Query.Fields.Single(f => f.Name == selection.Name.Value).ResolvedType; Type entityType = listGraphType.ResolvedType.GetType().GetGenericArguments()[0]; return(OeEdmClrHelper.GetEntitySet(_edmModel, entityType)); }
public override void AttachEntity(Object dataContext, ODataResourceBase entry) { var dbContext = (DbContext)dataContext; InternalEntityEntry internalEntry = GetEntityEntry(dbContext, entry); if (internalEntry == null) { Object entity = CreateEntity(dbContext, entry); EntityEntry entityEntry = dbContext.Attach(entity); AddInstanceAnnotation(entry, entityEntry); IReadOnlyList <IProperty> keyProperties = _entityType.FindPrimaryKey().Properties; foreach (ODataProperty odataProperty in entry.Properties) { IProperty property = _entityType.FindProperty(odataProperty.Name); if (!keyProperties.Contains(property)) { entityEntry.Property(property.Name).IsModified = true; } } } else { foreach (ODataProperty odataProperty in entry.Properties) { IProperty property = _entityType.FindProperty(odataProperty.Name); Object value = OeEdmClrHelper.GetClrValue(property.ClrType, odataProperty.Value); internalEntry.SetProperty(property, value, false); } } }
public override void AttachEntity(Object dataContext, ODataResourceBase entry) { var context = (T)dataContext; InternalEntityEntry internalEntry = GetEntityEntry(context, entry); if (internalEntry == null) { TEntity entity = CreateEntity(context, entry); _getEntitySet(context).Attach(entity); internalEntry = _getEntitySet(context).Attach(entity).GetInfrastructure(); IKey key = _entityType.FindPrimaryKey(); foreach (ODataProperty odataProperty in entry.Properties) { IProperty property = _entityType.FindProperty(odataProperty.Name); if (!key.Properties.Contains(property)) { internalEntry.SetPropertyModified(property); } } } else { foreach (ODataProperty odataProperty in entry.Properties) { IProperty property = _entityType.FindProperty(odataProperty.Name); Object value = OeEdmClrHelper.GetClrValue(property.ClrType, odataProperty.Value); internalEntry.SetProperty(property, value); } } }
private void Translate(OeNavigationSelectItem parentNavigationItem, ExpandedNavigationSelectItem item) { IEdmEntitySetBase entitySet = OeEdmClrHelper.GetEntitySet(_edmModel, item); OeNavigationSelectItemKind kind; if (_notSelected) { kind = OeNavigationSelectItemKind.NotSelected; } else if (item.SelectAndExpand.IsNextLink()) { kind = OeNavigationSelectItemKind.NextLink; } else { kind = OeNavigationSelectItemKind.Normal; } var childNavigationSelectItem = new OeNavigationSelectItem(entitySet, parentNavigationItem, item, kind); childNavigationSelectItem = parentNavigationItem.AddOrGetNavigationItem(childNavigationSelectItem); if (childNavigationSelectItem.Kind == OeNavigationSelectItemKind.NextLink) { return; } foreach (SelectItem selectItemClause in item.SelectAndExpand.SelectedItems) { Translate(childNavigationSelectItem, selectItemClause); } }
public MethodCallExpression Build(Expression outer, Expression inner, ODataPath odataPath, OrderByClause orderBy, long?skip, long?top) { var segment = (NavigationPropertySegment)odataPath.LastSegment; IEdmNavigationProperty navigationProperty = segment.NavigationProperty; if (navigationProperty.ContainsTarget) { ModelBuilder.ManyToManyJoinDescription joinDescription = _edmModel.GetManyToManyJoinDescription(navigationProperty); IEdmEntitySet joinEntitySet = OeEdmClrHelper.GetEntitySet(_edmModel, joinDescription.JoinNavigationProperty); outer = OeEnumerableStub.CreateEnumerableStubExpression(joinDescription.JoinClassType, joinEntitySet); navigationProperty = joinDescription.TargetNavigationProperty; } Type outerType = OeExpressionHelper.GetCollectionItemType(outer.Type); ParameterExpression outerParameter = Expression.Parameter(outerType, outerType.Name); inner = new ReplaceParameterVisitor(outerParameter).Visit(inner); //replace $it Expression subquery = CreateWhereExpression(outerParameter, inner, navigationProperty); subquery = _expressionBuilder.ApplyOrderBy(subquery, orderBy); subquery = _expressionBuilder.ApplySkip(subquery, skip, odataPath); subquery = _expressionBuilder.ApplyTake(subquery, top, odataPath); Type innerType = OeExpressionHelper.GetCollectionItemType(inner.Type); MethodInfo selectManyMethdoInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(outerType, innerType); return(Expression.Call(selectManyMethdoInfo, outer, Expression.Lambda(subquery, outerParameter))); }
public static async Task WriteCollectionAsync(IEdmModel edmModel, ODataUri odataUri, IAsyncEnumerator <Object> asyncEnumerator, Stream responseStream) { var importSegment = (OperationImportSegment)odataUri.Path.LastSegment; IEdmOperationImport operationImport = importSegment.OperationImports.Single(); Type returnType = edmModel.GetClrType(operationImport.Operation.ReturnType.Definition); IODataRequestMessage requestMessage = new Infrastructure.OeInMemoryMessage(responseStream, null); using (ODataMessageWriter messageWriter = new ODataMessageWriter(requestMessage, new ODataMessageWriterSettings() { EnableMessageStreamDisposal = false, ODataUri = odataUri }, edmModel)) { IEdmTypeReference typeRef = OeEdmClrHelper.GetEdmTypeReference(edmModel, returnType); ODataCollectionWriter writer = await messageWriter.CreateODataCollectionWriterAsync(typeRef).ConfigureAwait(false); await writer.WriteStartAsync(new ODataCollectionStart()).ConfigureAwait(false); while (await asyncEnumerator.MoveNextAsync().ConfigureAwait(false)) { Object value = asyncEnumerator.Current; if (value != null && value.GetType().IsEnum) { value = value.ToString(); } await writer.WriteItemAsync(value).ConfigureAwait(false); } await writer.WriteEndAsync().ConfigureAwait(false); } }
private static OeSkipTokenNameValue[] ParseJson(IEdmModel model, String skipToken, IEdmStructuralProperty[] keys) { var skipTokenNameValues = new OeSkipTokenNameValue[keys.Length]; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(skipToken))) { IODataRequestMessage requestMessage = new OeInMemoryMessage(stream, null); using (ODataMessageReader messageReader = new ODataMessageReader(requestMessage, ReaderSettings, model)) { var operation = new EdmAction("", "", null); foreach (IEdmStructuralProperty key in keys) { operation.AddParameter(GetPropertyName(key), key.Type); } ODataParameterReader reader = messageReader.CreateODataParameterReader(operation); int i = 0; while (reader.Read()) { Object value = reader.Value; if (value is ODataEnumValue enumValue) { value = OeEdmClrHelper.GetValue(model, enumValue); } skipTokenNameValues[i++] = new OeSkipTokenNameValue(reader.Name, value); } } } return(skipTokenNameValues); }
public MethodCallExpression Build(IEdmModel edmModel, Expression outerSource, Expression innerSource, IReadOnlyList <IEdmNavigationProperty> joinPath, IEdmNavigationProperty navigationProperty) { if (navigationProperty.ContainsTarget) { ModelBuilder.ManyToManyJoinDescription joinDescription = edmModel.GetManyToManyJoinDescription(navigationProperty); IEdmEntitySet joinEntitySet = OeEdmClrHelper.GetEntitySet(edmModel, joinDescription.JoinNavigationProperty); Expression joinSource = OeEnumerableStub.CreateEnumerableStubExpression(joinDescription.JoinClassType, joinEntitySet); outerSource = Build(outerSource, joinSource, joinPath, joinDescription.JoinNavigationProperty, false); AddJoinPath(joinPath, joinDescription.JoinNavigationProperty); var fixedJoinPath = new IEdmNavigationProperty[joinPath.Count + 1]; for (int i = 0; i < joinPath.Count; i++) { fixedJoinPath[i] = joinPath[i]; } fixedJoinPath[fixedJoinPath.Length - 1] = joinDescription.JoinNavigationProperty; outerSource = Build(outerSource, innerSource, fixedJoinPath, joinDescription.TargetNavigationProperty, true); _joinPaths.RemoveAt(_joinPaths.Count - 1); } else { outerSource = Build(outerSource, innerSource, joinPath, navigationProperty, false); } AddJoinPath(joinPath, navigationProperty); return((MethodCallExpression)outerSource); }
private MethodCallExpression?GetJoin(Expression outer, MemberExpression navigationProperty) { Type outerType = outer.Type; Type innerType = navigationProperty.Type; IEdmModel?edmModel = _edmModel.GetEdmModel(outerType); if (edmModel == null) { return(null); } Db.OeDataAdapter dataAdapter = edmModel.GetDataAdapter(edmModel.EntityContainer); Db.OeEntitySetAdapter?outerEntitySetAdapter = dataAdapter.EntitySetAdapters.Find(outerType); if (outerEntitySetAdapter == null) { throw new InvalidOperationException("OeEntitySetAdapter not found for type " + outerType.Name); } IEdmEntitySet outerEntitySet = OeEdmClrHelper.GetEntitySet(_edmModel, outerEntitySetAdapter.EntitySetName); IEdmNavigationProperty edmNavigationProperty = outerEntitySet.EntityType().NavigationProperties().Single(p => p.Name == navigationProperty.Member.Name); Db.OeEntitySetAdapter?innerEntitySetAdapter = dataAdapter.EntitySetAdapters.Find(innerType); if (innerEntitySetAdapter == null) { throw new InvalidOperationException("OeEntitySetAdapter not found for type " + innerType.Name); } IEdmEntitySet entitySet = edmModel.FindDeclaredEntitySet(innerEntitySetAdapter.EntitySetName); ConstantExpression innerSource = OeEnumerableStub.CreateEnumerableStubExpression(innerType, entitySet); return(GetJoin(outer, innerSource, edmNavigationProperty)); }
public override void RemoveEntity(Object dataContext, ODataResourceBase entry) { var context = (T)dataContext; InitKey(context); ObjectContext objectContext = ((IObjectContextAdapter)context).ObjectContext; var entity = (TEntity)OeEdmClrHelper.CreateEntity(EntityType, entry); EntityKey entityKey = objectContext.CreateEntityKey(EntitySetName, entity); if (objectContext.ObjectStateManager.TryGetObjectStateEntry(entityKey, out ObjectStateEntry objectStateEntry)) { objectStateEntry.ChangeState(EntityState.Deleted); } else { if (_isCascade && !_isSelfReference) { context.Entry(entity).State = EntityState.Deleted; } else { var keyValues = new Object[entityKey.EntityKeyValues.Length]; for (int i = 0; i < keyValues.Length; i++) { keyValues[i] = entityKey.EntityKeyValues[i].Value; } IDbSet <TEntity> dbSet = _getEntitySet(context); context.Entry(dbSet.Find(keyValues)).State = EntityState.Deleted; } } }
public override void AddEntity(Object dataContext, ODataResourceBase entry) { var entity = (TEntity)OeEdmClrHelper.CreateEntity(EntityType, entry); AddInstanceAnnotation(entry, entity); GetTable(dataContext).Insert(entity); }
public static IEnumerable <KeyValuePair <String, Object> > ParseJson(IEdmModel model, String skipToken, IEnumerable <IEdmStructuralProperty> keys) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(skipToken))) { IODataRequestMessage requestMessage = new OeInMemoryMessage(stream, null); using (ODataMessageReader messageReader = new ODataMessageReader(requestMessage, ReaderSettings, model)) { var operation = new EdmAction("", "", null); foreach (IEdmStructuralProperty key in keys) { operation.AddParameter(GetPropertyName(key), key.Type); } ODataParameterReader reader = messageReader.CreateODataParameterReader(operation); while (reader.Read()) { Object value = reader.Value; if (value is ODataEnumValue enumValue) { value = OeEdmClrHelper.GetValue(model, enumValue); } yield return(new KeyValuePair <String, Object>(reader.Name, value)); } } } }
public override void AttachEntity(Object dataContext, ODataResourceBase entry) { var entity = (TEntity)OeEdmClrHelper.CreateEntity(EntityType, entry); ObjectContext objectContext = ((IObjectContextAdapter)dataContext).ObjectContext; EntityKey entityKey = objectContext.CreateEntityKey(EntitySetName, entity); if (objectContext.ObjectStateManager.TryGetObjectStateEntry(entityKey, out ObjectStateEntry objectStateEntry)) { foreach (ODataProperty odataProperty in entry.Properties) { if (Array.Find(objectStateEntry.EntityKey.EntityKeyValues, k => k.Key == odataProperty.Name) == null) { int i = objectStateEntry.CurrentValues.GetOrdinal(odataProperty.Name); objectStateEntry.CurrentValues.SetValue(i, odataProperty.Value); } } } else { var context = (T)dataContext; _getEntitySet(context).Attach(entity); objectContext.ObjectStateManager.TryGetObjectStateEntry(entityKey, out objectStateEntry); foreach (ODataProperty odataProperty in entry.Properties) { if (Array.Find(objectStateEntry.EntityKey.EntityKeyValues, k => k.Key == odataProperty.Name) == null) { objectStateEntry.SetModifiedProperty(odataProperty.Name); } } } }
private static ClrTableTypeEdmSet[] GetOrderedTableTypes(IEdmModel edmModel, OeEntitySetAdapterCollection entitySetAdapters) { var clrTypeEdmSetList = new List <ClrTableTypeEdmSet>(); foreach (OeEntitySetAdapter entitySetAdapter in entitySetAdapters) { IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(edmModel, entitySetAdapter.EntitySetName); clrTypeEdmSetList.Add(new ClrTableTypeEdmSet(entitySetAdapter.EntityType, entitySet)); } var orderedTableTypeList = new List <ClrTableTypeEdmSet>(); while (clrTypeEdmSetList.Count > 0) { for (int i = 0; i < clrTypeEdmSetList.Count; i++) { if (IsDependent(clrTypeEdmSetList[i], clrTypeEdmSetList, out PropertyInfo selfRefProperty)) { Type linq2DbTableType = typeof(OeLinq2DbTable <>).MakeGenericType(clrTypeEdmSetList[i].ClrTableType); if (selfRefProperty != null) { linq2DbTableType.GetProperty(nameof(OeLinq2DbTable <Object> .SelfRefProperty)).SetValue(null, selfRefProperty); } orderedTableTypeList.Add(clrTypeEdmSetList[i]); clrTypeEdmSetList.RemoveAt(i); break; } } } return(orderedTableTypeList.ToArray()); }
private Expression GetInnerSource(OeSelectItem navigationItem, ExpandedNavigationSelectItem item) { Type clrEntityType = _visitor.EdmModel.GetClrType(navigationItem.EdmProperty.DeclaringType); PropertyInfo navigationClrProperty = OeEdmClrHelper.GetPropertyIgnoreCase(clrEntityType, navigationItem.EdmProperty); Type itemType = OeExpressionHelper.GetCollectionItemType(navigationClrProperty.PropertyType); if (itemType == null) { itemType = navigationClrProperty.PropertyType; } var visitor = new OeQueryNodeVisitor(_visitor, Expression.Parameter(itemType)); var expressionBuilder = new OeExpressionBuilder(_joinBuilder, visitor); Expression innerSource = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(itemType)); innerSource = expressionBuilder.ApplyFilter(innerSource, item.FilterOption); if (item.SkipOption != null || item.TopOption != null) { Expression source = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(navigationClrProperty.DeclaringType)); innerSource = OeCrossApplyBuilder.Build(source, innerSource, item, navigationItem.Path, expressionBuilder); } return(innerSource); }
private MethodCallExpression CreateSelectExpression(Expression source, OeJoinBuilder joinBuilder) { if (_navigationItem.HasNavigationItems) { return((MethodCallExpression)source); } if (_navigationItem.SelectItems.Count == 0) { return((MethodCallExpression)source); } var expressions = new List <Expression>(_navigationItem.SelectItems.Count); for (int i = 0; i < _navigationItem.SelectItems.Count; i++) { IEdmProperty edmProperty = _navigationItem.SelectItems[i].EdmProperty; PropertyInfo clrProperty = OeEdmClrHelper.GetPropertyIgnoreCase(_visitor.Parameter.Type, edmProperty); expressions.Add(Expression.MakeMemberAccess(_visitor.Parameter, clrProperty)); } NewExpression newTupleExpression = OeExpressionHelper.CreateTupleExpression(expressions); LambdaExpression lambda = Expression.Lambda(newTupleExpression, _visitor.Parameter); MethodInfo selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(_visitor.Parameter.Type, newTupleExpression.Type); return(Expression.Call(selectMethodInfo, source, lambda)); }
private Expression GetInnerSource(OeSelectItem navigationItem, ExpandedNavigationSelectItem item) { Type clrEntityType = _visitor.EdmModel.GetClrType(navigationItem.EdmProperty.DeclaringType); PropertyInfo navigationClrProperty = clrEntityType.GetPropertyIgnoreCase(navigationItem.EdmProperty); Type itemType = OeExpressionHelper.GetCollectionItemType(navigationClrProperty.PropertyType); if (itemType == null) { itemType = navigationClrProperty.PropertyType; } var visitor = new OeQueryNodeVisitor(_visitor, Expression.Parameter(itemType)); var expressionBuilder = new OeExpressionBuilder(_joinBuilder, visitor); var navigationEdmProperty = (IEdmNavigationProperty)navigationItem.EdmProperty; if (navigationEdmProperty.ContainsTarget) { ModelBuilder.ManyToManyJoinDescription joinDescription = _visitor.EdmModel.GetManyToManyJoinDescription(navigationEdmProperty); navigationEdmProperty = joinDescription.TargetNavigationProperty; } IEdmEntitySet innerEntitySet = OeEdmClrHelper.GetEntitySet(_visitor.EdmModel, navigationEdmProperty); Expression innerSource = OeEnumerableStub.CreateEnumerableStubExpression(itemType, innerEntitySet); innerSource = expressionBuilder.ApplyFilter(innerSource, item.FilterOption); if (item.SkipOption != null || item.TopOption != null) { Expression source = OeEnumerableStub.CreateEnumerableStubExpression(navigationClrProperty.DeclaringType, (IEdmEntitySet)_navigationItem.EntitySet); innerSource = OeCrossApplyBuilder.Build(source, innerSource, item, navigationItem.Path, expressionBuilder); } return(innerSource); }
public async Task ExecuteResultAsync(ActionContext context) { var settings = new ODataMessageWriterSettings() { BaseUri = _odataUri.ServiceRoot, EnableMessageStreamDisposal = false, ODataUri = _odataUri, Validations = ValidationKinds.ThrowIfTypeConflictsWithMetadata | ValidationKinds.ThrowOnDuplicatePropertyNames, Version = ODataVersion.V4 }; var requestHeaders = OeRequestHeaders.Parse(context.HttpContext.Request.Headers["Accept"], context.HttpContext.Request.Headers["Prefer"]); _metadataLevel = requestHeaders.MetadataLevel; if (requestHeaders.MaxPageSize > 0 && PageSize == 0) { PageSize = requestHeaders.MaxPageSize; } IODataResponseMessage responseMessage = new OeInMemoryMessage(context.HttpContext.Response.Body, context.HttpContext.Request.ContentType); using (ODataMessageWriter messageWriter = new ODataMessageWriter(responseMessage, settings, _edmModel)) { ODataUtils.SetHeadersForPayload(messageWriter, ODataPayloadKind.ResourceSet); IEdmEntitySet edmEntitySet = OeEdmClrHelper.GetEntitySet(_edmModel, typeof(T)); IEdmEntityType edmEntityType = edmEntitySet.EntityType(); ODataWriter writer = messageWriter.CreateODataResourceSetWriter(edmEntitySet, edmEntityType); await SerializeAsync(writer); } }
public static Db.OeBoundFunctionParameter CreateBoundFunctionParameter(OeQueryContext queryContext) { var expressionBuilder = new OeExpressionBuilder(queryContext.JoinBuilder); Type sourceEntityType = queryContext.EntitySetAdapter.EntityType; IEdmEntitySet sourceEntitySet = OeEdmClrHelper.GetEntitySet(queryContext.EdmModel, queryContext.EntitySetAdapter.EntitySetName); Expression source = OeEnumerableStub.CreateEnumerableStubExpression(sourceEntityType, sourceEntitySet); source = expressionBuilder.ApplyNavigation(source, queryContext.ParseNavigationSegments); IEdmEntitySet targetEntitySet = OeOperationHelper.GetEntitySet(queryContext.ODataUri.Path); if (sourceEntitySet != targetEntitySet) { queryContext.ODataUri.Path = new ODataPath(new EntitySetSegment(targetEntitySet)); } expressionBuilder = new OeExpressionBuilder(queryContext.JoinBuilder); Type targetEntityType = queryContext.EdmModel.GetClrType(targetEntitySet.EntityType()); Expression target = OeEnumerableStub.CreateEnumerableStubExpression(targetEntityType, targetEntitySet); target = expressionBuilder.ApplySelect(target, queryContext); var sourceQueryExpression = new OeQueryExpression(queryContext.EdmModel, sourceEntitySet, source); var targetQueryExpression = new OeQueryExpression(queryContext.EdmModel, targetEntitySet, target) { EntryFactory = expressionBuilder.CreateEntryFactory(targetEntitySet) }; Type boundFunctionParameterType = typeof(Db.OeBoundFunctionParameter <,>).MakeGenericType(new[] { sourceEntityType, targetEntityType }); ConstructorInfo ctor = boundFunctionParameterType.GetConstructor(new[] { typeof(OeQueryExpression), typeof(OeQueryExpression) }); return((Db.OeBoundFunctionParameter)ctor.Invoke(new Object[] { sourceQueryExpression, targetQueryExpression })); }
public override void AddEntity(Object dataContext, ODataResourceBase entry) { IDbSet <TEntity> dbSet = _getEntitySet((T)dataContext); var entity = (TEntity)OeEdmClrHelper.CreateEntity(EntityType, entry); dbSet.Add(entity); }
private void BuildCompute(ComputeClause computeClause) { foreach (ComputeExpression computeExpression in computeClause.ComputedItems) { Expression expression = _visitor.TranslateNode(computeExpression.Expression); IEdmTypeReference edmTypeReference = OeEdmClrHelper.GetEdmTypeReference(_visitor.EdmModel, expression.Type); _navigationItem.AddSelectItem(new OeSelectItem(new ComputeProperty(computeExpression.Alias, edmTypeReference, expression), false)); } }
private void BuildCompute(ComputeClause computeClause) { foreach (ComputeExpression computeExpression in computeClause.ComputedItems) { Expression expression = _visitor.TranslateNode(computeExpression.Expression); IEdmTypeReference edmTypeReference = OeEdmClrHelper.GetEdmTypeReference(_model, expression.Type); _selectItemInfos.Add(new SelectItemInfo(new ComputeProperty(computeExpression.Alias, edmTypeReference), expression)); } }
public override IEnumerable <String> GetPrimaryKey(String tableName) { IEdmEntityType edmEntityType = OeEdmClrHelper.GetEntitySet(_edmModel, tableName).EntityType(); foreach (IEdmStructuralProperty structuralProperty in edmEntityType.Key()) { yield return(structuralProperty.Name); } }
private static void FillParameters(IEdmModel edmModel, List <KeyValuePair <String, Object> > parameters, Stream requestStream, IEdmOperation operation, String contentType) { if (!operation.Parameters.Any()) { return; } IODataRequestMessage requestMessage = new Infrastructure.OeInMemoryMessage(requestStream, contentType); var settings = new ODataMessageReaderSettings() { EnableMessageStreamDisposal = false }; using (var messageReader = new ODataMessageReader(requestMessage, settings, edmModel)) { ODataParameterReader parameterReader = messageReader.CreateODataParameterReader(operation); while (parameterReader.Read()) { Object value; switch (parameterReader.State) { case ODataParameterReaderState.Value: { value = OeEdmClrHelper.GetValue(edmModel, parameterReader.Value); break; } case ODataParameterReaderState.Collection: { ODataCollectionReader collectionReader = parameterReader.CreateCollectionReader(); value = OeEdmClrHelper.GetValue(edmModel, ReadCollection(collectionReader)); break; } case ODataParameterReaderState.Resource: { ODataReader reader = parameterReader.CreateResourceReader(); value = OeEdmClrHelper.GetValue(edmModel, ReadResource(reader)); break; } case ODataParameterReaderState.ResourceSet: { ODataReader reader = parameterReader.CreateResourceSetReader(); value = OeEdmClrHelper.GetValue(edmModel, ReadResourceSet(reader)); break; } default: continue; } parameters.Add(new KeyValuePair <String, Object>(parameterReader.Name, value)); } } }
private OeEntryFactory CreateEntryFactory(OeExpressionBuilder expressionBuilder) { IEdmEntitySet entitySet = OeParseNavigationSegment.GetEntitySet(ParseNavigationSegments); if (entitySet == null) { entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, EntitySetAdapter.EntitySetName); } return(expressionBuilder.CreateEntryFactory(entitySet)); }
public override Task <int> SaveChangesAsync(Object dataContext, CancellationToken cancellationToken) { foreach (InMemoryEntitySetAdapter entitySetAdapter in base.EntitySetAdapters) { if (!entitySetAdapter.IsDbQuery) { foreach (PropertyInfo key in ModelBuilder.OeModelBuilderHelper.GetKeyProperties(entitySetAdapter.EntityType)) { if (key.PropertyType == typeof(int)) { foreach (Object entity in entitySetAdapter.GetSource(dataContext)) { var id = (int)key.GetValue(entity); if (id < 0) { key.SetValue(entity, -id); } } } } IEdmEntityType entityType = OeEdmClrHelper.GetEntitySet(_edmModel, entitySetAdapter.EntitySetName).EntityType(); foreach (IEdmNavigationProperty navigationProperty in entityType.NavigationProperties()) { IEnumerable <IEdmStructuralProperty> edmProperties = navigationProperty.DependentProperties(); if (edmProperties != null) { foreach (IEdmStructuralProperty edmProperty in edmProperties) { if (edmProperty.DeclaringType != entityType) { break; } PropertyInfo clrProperty = entitySetAdapter.EntityType.GetProperty(edmProperty.Name) !; if (clrProperty.PropertyType == typeof(int) || clrProperty.PropertyType == typeof(int?)) { foreach (Object entity in entitySetAdapter.GetSource(dataContext)) { var id = (int?)clrProperty.GetValue(entity); if (id < 0) { clrProperty.SetValue(entity, -id); } } } } } } } } return(base.SaveChangesAsync(dataContext, cancellationToken)); }
public static IReadOnlyList <KeyValuePair <String, Object?> > GetParameters(IEdmModel edmModel, ODataPathSegment segment, IDictionary <string, SingleValueNode> parameterAliasNodes, Stream?requestStream = null, String?contentType = null) { var parameters = new List <KeyValuePair <String, Object?> >(); IEdmOperation operation; IEnumerable <OperationSegmentParameter> segmentParameters; if (segment is OperationSegment operationSegment) { segmentParameters = operationSegment.Parameters; operation = operationSegment.Operations.Single(); } else if (segment is OperationImportSegment operationImportSegment) { segmentParameters = operationImportSegment.Parameters; operation = (EdmOperation)operationImportSegment.OperationImports.Single().Operation; } else { throw new InvalidOperationException("Not supported segment type " + segment.GetType().Name); } foreach (OperationSegmentParameter segmentParameter in segmentParameters) { Object?value; if (segmentParameter.Value is ConstantNode constantNode) { value = OeEdmClrHelper.GetValue(edmModel, constantNode.Value); } else if (segmentParameter.Value is ConvertNode convertNode) { value = OeEdmClrHelper.GetValue(edmModel, ((ConstantNode)convertNode.Source).Value); } else if (segmentParameter.Value is ParameterAliasNode parameterAliasNode) { value = OeEdmClrHelper.GetValue(edmModel, ((ConstantNode)parameterAliasNodes[parameterAliasNode.Alias]).Value); } else { value = OeEdmClrHelper.GetValue(edmModel, segmentParameter.Value); } parameters.Add(new KeyValuePair <String, Object?>(segmentParameter.Name, value)); } if (parameters.Count == 0 && requestStream != null) { FillParameters(edmModel, parameters, requestStream, operation, contentType); } OrderParameters(operation.Parameters, parameters); return(parameters); }
private OeEntryFactory CreateEntryFactory(OeExpressionBuilder expressionBuilder, OePropertyAccessor[] skipTokenAccessors) { IEdmEntitySet?entitySet = OeParseNavigationSegment.GetEntitySet(ParseNavigationSegments); if (entitySet == null) { entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, EntitySetAdapter.EntitySetName); } return(expressionBuilder.CreateEntryFactory(entitySet, skipTokenAccessors)); }
private OeEntryFactory CreateEntryFactory(OeExpressionBuilder expressionBuilder) { IEdmEntitySet entitySet = EntitySet; if (expressionBuilder.EntityType != EntitySetAdapter.EntityType) { entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, expressionBuilder.EntityType); } return(expressionBuilder.CreateEntryFactory(entitySet)); }
public EntitySetConfiguration <TEntityType> EntitySet <TEntityType>(String entitySetName) where TEntityType : class { IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, entitySetName); if (entitySet == null) { throw new InvalidOperationException("EntitySet " + entitySetName + " not found in EdmModel"); } return(new EntitySetConfiguration <TEntityType>(this, entitySet)); }