internal ComplexTypeConfiguration(ODataModelBuilder modelBuilder) : base(new ComplexTypeConfiguration(modelBuilder, typeof(TComplexType))) { }
public void CanBuildBoundProcedureCacheForIEdmModel() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType; customer.HasKey(c => c.ID); customer.Property(c => c.Name); customer.ComplexProperty(c => c.Address); EntityTypeConfiguration <Movie> movie = builder.EntitySet <Movie>("Movies").EntityType; movie.HasKey(m => m.ID); movie.HasKey(m => m.Name); EntityTypeConfiguration <Blockbuster> blockBuster = builder.EntityType <Blockbuster>().DerivesFrom <Movie>(); EntityTypeConfiguration movieConfiguration = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Single(t => t.Name == "Movie"); // build actions that are bindable to a single entity customer.Action("InCache1_CustomerAction"); customer.Action("InCache2_CustomerAction"); movie.Action("InCache3_MovieAction"); ActionConfiguration incache4_MovieAction = builder.Action("InCache4_MovieAction"); incache4_MovieAction.SetBindingParameter("bindingParameter", movieConfiguration); blockBuster.Action("InCache5_BlockbusterAction"); // build actions that are either: bindable to a collection of entities, have no parameter, have only complex parameter customer.Collection.Action("NotInCache1_CustomersAction"); movie.Collection.Action("NotInCache2_MoviesAction"); ActionConfiguration notInCache3_NoParameters = builder.Action("NotInCache3_NoParameters"); ActionConfiguration notInCache4_AddressParameter = builder.Action("NotInCache4_AddressParameter"); notInCache4_AddressParameter.Parameter <Address>("address"); IEdmModel model = builder.GetEdmModel(); IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Customer"); IEdmEntityType movieType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Movie"); IEdmEntityType blockBusterType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Blockbuster"); // Act BindableProcedureFinder annotation = new BindableProcedureFinder(model); IEdmAction[] movieActions = annotation.FindProcedures(movieType) .OfType <IEdmAction>() .ToArray(); IEdmAction[] customerActions = annotation.FindProcedures(customerType) .OfType <IEdmAction>() .ToArray(); IEdmAction[] blockBusterActions = annotation.FindProcedures(blockBusterType) .OfType <IEdmAction>() .ToArray(); // Assert Assert.Equal(2, customerActions.Length); Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache1_CustomerAction")); Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache2_CustomerAction")); Assert.Equal(2, movieActions.Length); Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction")); Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction")); Assert.Equal(3, blockBusterActions.Length); Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction")); Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction")); Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache5_BlockbusterAction")); }
/// <summary> /// Initializes a new instance of the <see cref="EntityTypeConfiguration"/> class. /// </summary> /// <param name="modelBuilder">The <see cref="ODataModelBuilder"/> being used.</param> /// <param name="clrType">The backing CLR type for this entity type.</param> public EntityTypeConfiguration(ODataModelBuilder modelBuilder, Type clrType) : base(modelBuilder, clrType) { }
/// <summary> /// Initializes a new instance of <see cref="EntityTypeConfiguration"/>. /// </summary> /// <param name="modelBuilder">The <see cref="ODataModelBuilder"/> being used.</param> internal EntityTypeConfiguration(ODataModelBuilder modelBuilder) : this(modelBuilder, new EntityTypeConfiguration(modelBuilder, typeof(TEntityType))) { }
/// <summary> /// Initializes a new instance of <see cref="ProcedureConfiguration" /> class. /// </summary> /// <param name="builder">The ODataModelBuilder to which this ProcedureConfiguration should be added.</param> /// <param name="name">The name of this ProcedureConfiguration.</param> internal ProcedureConfiguration(ODataModelBuilder builder, string name) { Name = name; ModelBuilder = builder; }
/// <summary> /// Gets the annotation configurations associated with the specified model builder. /// </summary> /// <param name="modelBuilder">The <see cref="ODataModelBuilder">model builder</see> get the annotation configurations for.</param> /// <returns>A <see cref="AnnotationConfigurationCollection">collection</see> of <see cref="IAnnotationConfiguration">annotation configurations</see>.</returns> public static AnnotationConfigurationCollection GetAnnotationConfigurations(this ODataModelBuilder modelBuilder) { Arg.NotNull(modelBuilder, nameof(modelBuilder)); Contract.Ensures(Contract.Result <AnnotationConfigurationCollection>() != null); return(annotationConfigurations.GetOrAdd(modelBuilder, b => new AnnotationConfigurationCollection())); }
public void CreateModelUsingProgrammableApi() { var builder = new ODataModelBuilder(); var customerConfig = builder.AddEntityType(typeof(Customer)); customerConfig.HasKey(typeof(Customer).GetProperty("CustomerId")); customerConfig.AddProperty(typeof(Customer).GetProperty("Name")); var ordersPropertyConfig = customerConfig.AddNavigationProperty(typeof(Customer).GetProperty("Orders"), EdmMultiplicity.Many); var orderConfig = builder.AddEntityType(typeof(Order)); orderConfig.HasKey(typeof(Order).GetProperty("OrderId")); orderConfig.AddProperty(typeof(Order).GetProperty("Cost")); var customersSetConfig = builder.AddEntitySet("Customers", customerConfig); var ordersSetConfig = builder.AddEntitySet("Orders", orderConfig); customersSetConfig.AddBinding(ordersPropertyConfig, ordersSetConfig); var meConfig = builder.AddSingleton("Me", customerConfig); var model = builder.GetServiceModel(); var customerType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Customer"); Assert.NotNull(customerType); Assert.Equal(typeof(Customer).Namespace, customerType.Namespace); Assert.Equal(3, customerType.DeclaredProperties.Count()); var key = customerType.DeclaredKey.SingleOrDefault(); Assert.NotNull(key); Assert.Equal("CustomerId", key.Name); Assert.True(key.Type.IsInt32()); Assert.False(key.Type.IsNullable); var nameProperty = customerType.DeclaredProperties.SingleOrDefault(dp => dp.Name == "Name"); Assert.NotNull(nameProperty); Assert.True(nameProperty.Type.IsString()); Assert.True(nameProperty.Type.IsNullable); Assert.Equal(1, customerType.NavigationProperties().Count()); var ordersProperty = customerType.NavigationProperties().Single(); Assert.Equal("Orders", ordersProperty.Name); Assert.Equal(EdmTypeKind.Collection, ordersProperty.Type.Definition.TypeKind); Assert.Equal(typeof(Order).FullName, (ordersProperty.Type.Definition as IEdmCollectionType).ElementType.FullName()); var entityContainer = model.EntityContainer; Assert.NotNull(entityContainer); var customers = entityContainer.FindEntitySet("Customers"); Assert.NotNull(customers); Assert.Equal(typeof(Customer).FullName, customers.EntityType().FullName()); var orders = entityContainer.FindEntitySet("Orders"); Assert.NotNull(orders); Assert.Equal(typeof(Order).FullName, orders.EntityType().FullName()); var me = entityContainer.FindSingleton("Me"); Assert.NotNull(me); Assert.Equal(typeof(Customer).FullName, me.EntityType().FullName()); }
public void CanEmitModelWithTwoEntitiesAndARelationship() { var builder = new ODataModelBuilder().Add_Order_EntityType().Add_Customer_EntityType().Add_CustomerOrders_Relationship(); var model = builder.GetServiceModel(); var csdl = GetCSDL(model); }
public void CanCreateEdmModel_ForBindableFunction_WithSupportedParameterType() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); customer.HasKey(c => c.CustomerId); customer.Property(c => c.Name); // Act FunctionConfiguration functionBuilder = customer.Function("FunctionName"); functionBuilder.Parameter <int>("primitive"); functionBuilder.CollectionParameter <int>("collectionPrimitive"); functionBuilder.Parameter <bool?>("nullablePrimitive"); functionBuilder.CollectionParameter <bool?>("nullableCollectionPrimitive"); functionBuilder.Parameter <Color>("enum"); functionBuilder.CollectionParameter <Color>("collectionEnum"); functionBuilder.Parameter <Color?>("nullableEnum"); functionBuilder.CollectionParameter <Color?>("nullableCollectionEnum"); functionBuilder.Parameter <Address>("complex"); functionBuilder.CollectionParameter <Address>("collectionComplex"); functionBuilder.EntityParameter <Customer>("entity"); functionBuilder.CollectionEntityParameter <Customer>("collectionEntity"); functionBuilder.Returns <bool>(); IEdmModel model = builder.GetEdmModel(); // Assert Assert.Equal(1, model.SchemaElements.OfType <IEdmFunction>().Count()); IEdmFunction function = Assert.Single(model.SchemaElements.OfType <IEdmFunction>()); Assert.False(function.IsComposable); Assert.True(function.IsBound); Assert.Equal("FunctionName", function.Name); Assert.NotNull(function.ReturnType); Assert.Equal(13, function.Parameters.Count()); function.AssertHasParameter(model, BindingParameterConfiguration.DefaultBindingParameterName, typeof(Customer), true); function.AssertHasParameter(model, parameterName: "primitive", parameterType: typeof(int), isNullable: false); function.AssertHasParameter(model, parameterName: "collectionPrimitive", parameterType: typeof(IList <int>), isNullable: false); function.AssertHasParameter(model, parameterName: "nullablePrimitive", parameterType: typeof(bool?), isNullable: true); function.AssertHasParameter(model, parameterName: "nullableCollectionPrimitive", parameterType: typeof(IList <bool?>), isNullable: true); function.AssertHasParameter(model, parameterName: "enum", parameterType: typeof(Color), isNullable: false); function.AssertHasParameter(model, parameterName: "collectionEnum", parameterType: typeof(IList <Color>), isNullable: false); function.AssertHasParameter(model, parameterName: "nullableEnum", parameterType: typeof(Color?), isNullable: true); function.AssertHasParameter(model, parameterName: "nullableCollectionEnum", parameterType: typeof(IList <Color?>), isNullable: true); function.AssertHasParameter(model, parameterName: "complex", parameterType: typeof(Address), isNullable: true); function.AssertHasParameter(model, parameterName: "collectionComplex", parameterType: typeof(IList <Address>), isNullable: true); function.AssertHasParameter(model, parameterName: "entity", parameterType: typeof(Customer), isNullable: true); function.AssertHasParameter(model, parameterName: "collectionEntity", parameterType: typeof(IList <Customer>), isNullable: true); }
public void MaxDataServiceVersion_RoundTrips() { ODataModelBuilder builder = new ODataModelBuilder(); Assert.Reflection.Property(builder, b => b.MaxDataServiceVersion, new Version(4, 0), allowNull: false, roundTripTestValue: new Version(1, 0)); }
/// <summary> /// Initializes a new instance of <see cref="FunctionConfiguration" /> class. /// </summary> /// <param name="builder">The ODataModelBuilder to which this FunctionConfiguration should be added.</param> /// <param name="name">The name of this FunctionConfiguration.</param> internal FunctionConfiguration(ODataModelBuilder builder, string name) : base(builder, name) { // By default, function import is included in service document IncludeInServiceDocument = true; }
/// <summary> /// Initializes a new instance of the <see cref="NavigationSourceConfiguration"/> class. /// </summary> /// <param name="modelBuilder">The <see cref="ODataModelBuilder"/>.</param> /// <param name="entityClrType">The <see cref="Type"/> of the entity type contained in this navigation source.</param> /// <param name="name">The name of the navigation source.</param> protected NavigationSourceConfiguration(ODataModelBuilder modelBuilder, Type entityClrType, string name) : this(modelBuilder, new EntityTypeConfiguration(modelBuilder, entityClrType), name) { }
internal EntitySetConfiguration(ODataModelBuilder modelBuilder, string name) : this(modelBuilder, new EntitySetConfiguration(modelBuilder, typeof(TEntityType), name)) { }
public void CanEmitModelWithSingleEntity() { var builder = new ODataModelBuilder().Add_Customer_EntityType(); var model = builder.GetServiceModel(); var csdl = GetCSDL(model); }
public void CanBuildProcedureBoundToCollectionCacheForIEdmModel() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType; customer.HasKey(c => c.ID); customer.Property(c => c.Name); customer.ComplexProperty(c => c.Address); EntityTypeConfiguration <Movie> movie = builder.EntitySet <Movie>("Movies").EntityType; movie.HasKey(m => m.ID); movie.HasKey(m => m.Name); EntityTypeConfiguration <Blockbuster> blockBuster = builder.EntityType <Blockbuster>().DerivesFrom <Movie>(); EntityTypeConfiguration movieConfiguration = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Single(t => t.Name == "Movie"); // build actions that are bindable to the collection of entity customer.Collection.Action("CollectionCustomerActionInCache1"); customer.Collection.Action("CollectionCustomerActionInCache2"); movie.Collection.Action("CollectionMovieActionInCache3"); ActionConfiguration movieActionIncache4 = builder.Action("CollectionMovieActionInCache4"); CollectionTypeConfiguration collectionConfiguration = new CollectionTypeConfiguration(movieConfiguration, typeof(Movie)); movieActionIncache4.SetBindingParameter("bindingParameter", collectionConfiguration); blockBuster.Collection.Action("CollectionBlockbusterActionInCache5"); // build functions that are bindable to the collection of entity customer.Collection.Function("CollectionCustomerFunctionInCache1").Returns <int>(); customer.Collection.Function("CollectionCustomerFunctionInCache2").Returns <int>(); movie.Collection.Function("CollectionMovieFunctionInCache3").Returns <int>(); blockBuster.Collection.Function("CollectionBlockbusterFunctionInCache5").Returns <int>(); // build actions that are either: bindable to an entity, have no parameter, have only complex parameter customer.Action("CustomersActionNotInCache1"); customer.Function("CustomersFunctionNotInCache1").Returns <int>(); movie.Action("MoviesActionNotInCache2"); builder.Action("NoParametersNotInCache3"); ActionConfiguration addressParameterNotInCache4 = builder.Action("AddressParameterNotInCache4"); addressParameterNotInCache4.Parameter <Address>("address"); IEdmModel model = builder.GetEdmModel(); IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Customer"); IEdmEntityType movieType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Movie"); IEdmEntityType blockBusterType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Blockbuster"); // Act BindableProcedureFinder annotation = new BindableProcedureFinder(model); var movieOperations = annotation.FindProceduresBoundToCollection(movieType).ToArray(); var customerOperations = annotation.FindProceduresBoundToCollection(customerType).ToArray(); var blockBusterOperations = annotation.FindProceduresBoundToCollection(blockBusterType).ToArray(); // Assert Assert.Equal(3, movieOperations.Length); Assert.Single(movieOperations.Where(a => a.Name == "CollectionMovieActionInCache3")); Assert.Single(movieOperations.Where(a => a.Name == "CollectionMovieActionInCache4")); Assert.Single(movieOperations.Where(a => a.Name == "CollectionMovieFunctionInCache3")); Assert.Equal(4, customerOperations.Length); Assert.Single(customerOperations.Where(a => a.Name == "CollectionCustomerActionInCache1")); Assert.Single(customerOperations.Where(a => a.Name == "CollectionCustomerActionInCache2")); Assert.Single(customerOperations.Where(a => a.Name == "CollectionCustomerFunctionInCache1")); Assert.Single(customerOperations.Where(a => a.Name == "CollectionCustomerFunctionInCache2")); Assert.Equal(5, blockBusterOperations.Length); Assert.Single(blockBusterOperations.Where(a => a.Name == "CollectionBlockbusterActionInCache5")); Assert.Single(blockBusterOperations.Where(a => a.Name == "CollectionBlockbusterFunctionInCache5")); Assert.Single(blockBusterOperations.Where(a => a.Name == "CollectionMovieActionInCache3")); Assert.Single(blockBusterOperations.Where(a => a.Name == "CollectionMovieActionInCache4")); Assert.Single(blockBusterOperations.Where(a => a.Name == "CollectionMovieFunctionInCache3")); }
public void CanEmitModelWithSingleComplexType() { var builder = new ODataModelBuilder().Add_Address_ComplexType(); var model = builder.GetServiceModel(); var csdl = GetCSDL(model); }
public EntitySetConfigurationTest() { _builder = new ODataModelBuilder(); _entityset = new EntitySetConfiguration(_builder, typeof(EntitySetConfigurationTest), "entityset"); }
private static IDictionary <string, EdmNavigationSource> GetNavigationSourceMap(this EdmModel model, ODataModelBuilder builder, Dictionary <Type, IEdmType> edmTypeMap, IEnumerable <NavigationSourceAndAnnotations> navigationSourceAndAnnotations) { // index the navigation source by name Dictionary <string, EdmNavigationSource> edmNavigationSourceMap = navigationSourceAndAnnotations.ToDictionary(e => e.NavigationSource.Name, e => e.NavigationSource); // apply the annotations foreach (NavigationSourceAndAnnotations navigationSourceAndAnnotation in navigationSourceAndAnnotations) { EdmNavigationSource navigationSource = navigationSourceAndAnnotation.NavigationSource; model.SetAnnotationValue <NavigationSourceUrlAnnotation>(navigationSource, navigationSourceAndAnnotation.Url); model.SetNavigationSourceLinkBuilder(navigationSource, navigationSourceAndAnnotation.LinkBuilder); AddNavigationBindings(navigationSourceAndAnnotation.Configuration, navigationSource, navigationSourceAndAnnotation.LinkBuilder, builder, edmTypeMap, edmNavigationSourceMap); } return(edmNavigationSourceMap); }
/// <summary> /// Initializes a new instance of the <see cref="ComplexTypeConfiguration"/> class. /// <param name="modelBuilder">The <see cref="ODataModelBuilder"/> being used.</param> /// <param name="clrType">The backing CLR type for this entity type.</param> /// </summary> public ComplexTypeConfiguration(ODataModelBuilder modelBuilder, Type clrType) : base(modelBuilder, clrType) { }
/// <summary> /// Initializes a new instance of <see cref="ActionConfiguration" /> class. /// </summary> /// <param name="builder">The ODataModelBuilder to which this ActionConfiguration should be added.</param> /// <param name="name">The name of this ActionConfiguration.</param> internal ActionConfiguration(ODataModelBuilder builder, string name) : base(builder, name) { }
/// <summary> /// Initializes a new instance of the <see cref="EntitySetConfiguration"/> class. /// </summary> /// <param name="modelBuilder">The <see cref="ODataModelBuilder"/>.</param> /// <param name="entityType">The entity type <see cref="EntityTypeConfiguration"/> contained in this entity set.</param> /// <param name="name">The name of the entity set.</param> public EntitySetConfiguration(ODataModelBuilder modelBuilder, EntityTypeConfiguration entityType, string name) : base(modelBuilder, entityType, name) { }