本文整理汇总了C#中Microsoft.Test.Taupo.Contracts.EntityModel.EntityModelSchema.Add方法的典型用法代码示例。如果您正苦于以下问题:C# EntityModelSchema.Add方法的具体用法?C# EntityModelSchema.Add怎么用?C# EntityModelSchema.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Test.Taupo.Contracts.EntityModel.EntityModelSchema
的用法示例。
在下文中一共展示了EntityModelSchema.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseSingleXsdl
/// <summary>
/// Parses a single csdl/ssdl file.
/// </summary>
/// <param name="model">the entity model schema which the csdl/ssdl file parses to</param>
/// <param name="schemaElement">the top level schema element in the csdl/ssdl file</param>
protected virtual void ParseSingleXsdl(EntityModelSchema model, XElement schemaElement)
{
this.AssertXsdlElement(schemaElement, "Schema");
this.SetupNamespaceAndAliases(schemaElement);
foreach (var entityContainerElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityContainer")))
{
model.Add(this.ParseEntityContainer(entityContainerElement));
}
foreach (var entityTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityType")))
{
model.Add(this.ParseEntityType(entityTypeElement));
}
foreach (var associationTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Association")))
{
model.Add(this.ParseAssociation(associationTypeElement));
}
foreach (var functionElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Function")))
{
model.Add(this.ParseFunction(functionElement));
}
}
示例2: Improve
/// <summary>
/// Improve the model if goals not yet met
/// </summary>
/// <param name="model">model to improve</param>
public override void Improve(EntityModelSchema model)
{
var roots = this.GetInheritanceRoots(model);
int numberOfRootsToAdd = this.MinNumberOfInheritanceRoots - roots.Count();
for (int i = 0; i < numberOfRootsToAdd; i++)
{
var root = new EntityType();
model.Add(root);
model.Add(new EntityType() { BaseType = root });
}
}
示例3: Improve
/// <summary>
/// Improve the model if goals not yet met
/// </summary>
/// <param name="model">model to improve</param>
public override void Improve(EntityModelSchema model)
{
var baseType = new EntityType();
model.Add(baseType);
for (int i = 0; i < this.MinNumberOfInheritanceLevels; i++)
{
var derivedType = new EntityType() { BaseType = baseType };
model.Add(derivedType);
baseType = derivedType;
}
}
示例4: ConvertToTaupoModel
/// <summary>
/// Converts a model from Edm term into Taupo term
/// </summary>
/// <param name="edmModel">The input model in Edm term</param>
/// <returns>The output model in Taupo term</returns>
public EntityModelSchema ConvertToTaupoModel(IEdmModel edmModel)
{
this.edmModel = edmModel;
this.associationRegistry = new AssociationRegistry();
var taupoModel = new EntityModelSchema();
foreach (var edmComplexType in edmModel.SchemaElements.OfType<IEdmComplexType>())
{
ComplexType taupoComplexType = this.ConvertToTaupoComplexType(edmComplexType);
taupoModel.Add(taupoComplexType);
}
foreach (var edmEntityType in edmModel.SchemaElements.OfType<IEdmEntityType>())
{
EntityType taupoEntityType = this.ConvertToTaupoEntityType(edmEntityType);
taupoModel.Add(taupoEntityType);
// convert to Association using information inside Navigations
foreach (var edmNavigationProperty in edmEntityType.DeclaredNavigationProperties())
{
if (!this.associationRegistry.IsAssociationRegistered(edmNavigationProperty))
{
this.associationRegistry.RegisterAssociation(edmNavigationProperty);
}
}
}
var edmEntityContainer = edmModel.EntityContainer;
if (edmEntityContainer != null)
{
EntityContainer taupoEntityContainer = this.ConvertToTaupoEntityContainer(edmEntityContainer);
taupoModel.Add(taupoEntityContainer);
}
foreach (var edmFunction in edmModel.SchemaElements.OfType<IEdmOperation>())
{
Function taupoFunction = this.ConvertToTaupoFunction(edmFunction);
taupoModel.Add(taupoFunction);
}
foreach (var edmEnum in edmModel.SchemaElements.OfType<IEdmEnumType>())
{
EnumType taupoEnumType = this.ConvertToTaupoEnumType(edmEnum);
taupoModel.Add(taupoEnumType);
}
return taupoModel.Resolve();
}
示例5: Improve
/// <summary>
/// Improve the model if goals not yet met
/// </summary>
/// <param name="model">model to improve</param>
public override void Improve(EntityModelSchema model)
{
while (model.EntityTypes.Count() < this.MinNumberOfEntities)
{
model.Add(new EntityType());
}
}
示例6: Fixup
/// <summary>
/// Add default EntityContainer to the given EntitySchemaModel
/// For each base entity type, add an EntitySet
/// For each association, add an AssociationSet, between two possible EntitySets
/// </summary>
/// <param name="model">the given EntitySchemaModel</param>
public void Fixup(EntityModelSchema model)
{
EntityContainer container = model.EntityContainers.FirstOrDefault();
if (container == null)
{
container = new EntityContainer(this.DefaultContainerName);
model.Add(container);
}
foreach (EntityType entity in model.EntityTypes.Where(e => e.BaseType == null && !container.EntitySets.Any(set => set.EntityType == e)))
{
if (!entity.Annotations.OfType<FixupNoSetAnnotation>().Any())
{
container.Add(new EntitySet(entity.Name, entity));
}
}
foreach (AssociationType association in model.Associations.Where(assoc => !container.AssociationSets.Any(assocSet => assocSet.AssociationType == assoc)))
{
if (!association.Annotations.OfType<FixupNoSetAnnotation>().Any())
{
container.Add(new AssociationSet(association.Name, association)
{
Ends =
{
new AssociationSetEnd(association.Ends[0], container.EntitySets.First(es => association.Ends[0].EntityType.IsKindOf(es.EntityType))),
new AssociationSetEnd(association.Ends[1], container.EntitySets.First(es => association.Ends[1].EntityType.IsKindOf(es.EntityType))),
}
});
}
}
}
示例7: Improve
/// <summary>
/// Improve the model if goals not yet met
/// </summary>
/// <param name="model">model to improve</param>
public override void Improve(EntityModelSchema model)
{
var baseTypes = model.EntityTypes.Where(e => model.EntityTypes.Any(d => d.BaseType == e)).ToList();
foreach (var baseType in baseTypes)
{
int numberOfSiblingsToAdd = this.MinNumberOfInheritanceSiblings - model.EntityTypes.Count(d => d.BaseType == baseType);
for (int i = 0; i < numberOfSiblingsToAdd; i++)
{
var derivedType = new EntityType() { BaseType = baseType };
model.Add(derivedType);
}
}
}
示例8: Fixup
/// <summary>
/// Adds a Function for each base entity type, representing a service operation
/// </summary>
/// <param name="model">the entity model</param>
public void Fixup(EntityModelSchema model)
{
foreach (var entityType in model.EntityTypes.Where(type => type.BaseType == null))
{
var entityName = entityType.Name;
model.Add(
new Function("Get" + entityName)
{
ReturnType = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName(entityName)),
Annotations =
{
new LegacyServiceOperationAnnotation
{
Method = HttpVerb.Get,
ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
},
AddRootServiceOperationsFixup.BuildReturnEntitySetFunctionBody(entityName),
},
});
}
}
示例9: Fixup
/// <summary>
/// Adds and updates existing types in the default model to use Primitive and Complex Collections
/// </summary>
/// <param name="model">Model to add fixup to.</param>
public void Fixup(EntityModelSchema model)
{
// Create entityType with all PrimitiveTypes lists
EntityType allPrimitiveCollectionTypesEntity = new EntityType("AllPrimitiveCollectionTypesEntity");
allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
allPrimitiveCollectionTypesEntity.Properties[0].IsPrimaryKey = true;
for (int i = 0; i < primitiveTypes.Length; i++)
{
DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Property" + i, t));
}
model.Add(allPrimitiveCollectionTypesEntity);
// Create a complexType with all PrimitiveTypes Bags and primitive properties in it
ComplexType additionalComplexType = new ComplexType("AdditionalComplexType");
additionalComplexType.Add(new MemberProperty("Bag1", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())));
additionalComplexType.Add(new MemberProperty("Bag3", EdmDataTypes.String()));
model.Add(additionalComplexType);
// Create a complexType with all PrimitiveTypes Bags in it
ComplexType complexPrimitiveCollectionsType = new ComplexType("ComplexTypePrimitiveCollections");
for (int i = 0; i < primitiveTypes.Length; i++)
{
DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
complexPrimitiveCollectionsType.Add(new MemberProperty("Property" + i, t));
}
complexPrimitiveCollectionsType.Add(new MemberProperty("ComplexTypeBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(additionalComplexType))));
model.Add(complexPrimitiveCollectionsType);
// Add the complexPrimitiveCollectionsType to an entity
EntityType complexBagsEntity = new EntityType("ComplexBagsEntity");
complexBagsEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
complexBagsEntity.Properties[0].IsPrimaryKey = true;
DataType complexDataType = DataTypes.ComplexType.WithDefinition(complexPrimitiveCollectionsType);
complexBagsEntity.Add(new MemberProperty("CollectionComplexTypePrimitiveCollections", DataTypes.CollectionType.WithElementDataType(complexDataType)));
complexBagsEntity.Add(new MemberProperty("ComplexTypePrimitiveCollections", complexDataType));
model.Add(complexBagsEntity);
int numberOfComplexCollections = 0;
// Update existing model so that every 3rd complexType is a Collection of ComplexTypes
foreach (EntityType t in model.EntityTypes)
{
foreach (MemberProperty complexProperty in t.Properties.Where(p => p.PropertyType is ComplexDataType).ToList())
{
// Remove existing one
t.Properties.Remove(complexProperty);
// Add new one
t.Properties.Add(new MemberProperty(complexProperty.Name + "Collection", DataTypes.CollectionType.WithElementDataType(complexProperty.PropertyType)));
numberOfComplexCollections++;
if (numberOfComplexCollections > 4)
{
break;
}
}
if (numberOfComplexCollections > 4)
{
break;
}
}
new ResolveReferencesFixup().Fixup(model);
// ReApply the previously setup namespace on to the new types
new ApplyDefaultNamespaceFixup(model.EntityTypes.First().NamespaceName).Fixup(model);
new AddDefaultContainerFixup().Fixup(model);
new SetDefaultCollectionTypesFixup().Fixup(model);
}
示例10: AddServiceOperationsToModel
private void AddServiceOperationsToModel(EntityModelSchema model)
{
model.Add(new Function("GetActor")
{
ReturnType = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Actor")),
Annotations =
{
new LegacyServiceOperationAnnotation
{
Method = HttpVerb.Get,
ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
},
new FunctionBodyAnnotation
{
//// Enable the following line to add this to root query for cross feature testing
//// IsRoot = true,
FunctionBodyGenerator = (schema) =>
{
var entitySet = schema.GetDefaultEntityContainer().EntitySets.Single(es => es.Name.Equals("Actor"));
return CommonQueryBuilder.Root(entitySet);
},
},
}
});
model.Add(new Function("GetPrimitiveString")
{
ReturnType = EdmDataTypes.String().NotNullable(),
Annotations =
{
new LegacyServiceOperationAnnotation
{
Method = HttpVerb.Get,
},
new FunctionBodyAnnotation
{
FunctionBody = CommonQueryBuilder.Constant("Foo"),
},
},
});
// Add a service operation that requires parameter
model.Add(new Function("GetArgumentPlusOne")
{
ReturnType = EdmDataTypes.Int32.NotNullable(),
Annotations =
{
new LegacyServiceOperationAnnotation
{
Method = HttpVerb.Get,
},
new FunctionBodyAnnotation
{
FunctionBody = CommonQueryBuilder.Add(CommonQueryBuilder.FunctionParameterReference("arg1"), CommonQueryBuilder.Constant((int)1)),
},
},
Parameters =
{
new FunctionParameter("arg1", EdmDataTypes.Int32.NotNullable()),
},
});
// Add a WebInvoke service operation
model.Add(
new Function("WebInvokeGetMovie")
{
ReturnType = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Movie")),
Annotations =
{
new LegacyServiceOperationAnnotation
{
Method = HttpVerb.Post,
ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
},
new FunctionBodyAnnotation
{
//// Enable the following line to add this to root query for cross feature testing
//// IsRoot = true,
FunctionBodyGenerator = (schema) =>
{
var entitySet = schema.GetDefaultEntityContainer().EntitySets.Single(es => es.Name.Equals("Movie"));
return CommonQueryBuilder.Root(entitySet);
},
}
},
});
model.Add(
new Function("WebInvokeGetMovieWithParameter")
{
ReturnType = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Movie")),
Annotations =
{
new LegacyServiceOperationAnnotation
{
Method = HttpVerb.Post,
ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
},
//.........这里部分代码省略.........
示例11: GenerateModel
public EntityModelSchema GenerateModel()
{
this.useDataTypes = new Dictionary<DataType, bool>();
var model = new EntityModelSchema()
{
new EntityType("Movie")
{
Annotations =
{
new HasStreamAnnotation(),
},
Properties =
{
new MemberProperty("Id", EdmDataTypes.Int32) { IsPrimaryKey = true },
new MemberProperty("Name", EdmDataTypes.String()),
new MemberProperty("LengthInMinutes", EdmDataTypes.Int32) { Annotations = { new ConcurrencyTokenAnnotation() } },
new MemberProperty("ReleaseYear", EdmDataTypes.DateTime()),
new MemberProperty("Trailer", EdmDataTypes.Stream),
new MemberProperty("FullMovie", EdmDataTypes.Stream),
new MemberProperty("IsAwardWinner", EdmDataTypes.Boolean),
new MemberProperty("AddToQueueValue", EdmDataTypes.Boolean),
new MemberProperty("AddToQueueValue2", EdmDataTypes.Boolean),
new MemberProperty("MovieHomePage", EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(10)),
new MemberProperty("Description", EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(10)),
},
NavigationProperties =
{
new NavigationProperty("MovieRatings", "MovieRating_Movie", "Movie", "MovieRating"),
new NavigationProperty("Actors", "Movies_Actors", "Movies", "Actors"),
}
},
new ComplexType("Phone")
{
new MemberProperty("PhoneNumber", EdmDataTypes.String()),
new MemberProperty("Extension", EdmDataTypes.String().Nullable(true)),
},
new ComplexType("ContactDetails")
{
new MemberProperty("PhoneMultiValue", DataTypes.CollectionOfComplex("Phone")),
},
new ComplexType("Rating")
{
new MemberProperty("Comments", EdmDataTypes.String()),
new MemberProperty("FiveStarRating", EdmDataTypes.Byte),
new MemberProperty("Tags", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
},
new ComplexType("AllSpatialTypesComplex")
{
new MemberProperty("Geog", EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogPoint", EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogLine", EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogPolygon", EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogCollection", EdmDataTypes.GeographyCollection.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogMultiPoint", EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogMultiLine", EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeogMultiPolygon", EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("Geom", EdmDataTypes.Geometry.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomPoint", EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomLine", EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomPolygon", EdmDataTypes.GeometryPolygon.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomCollection", EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomMultiPoint", EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomMultiLine", EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
new MemberProperty("GeomMultiPolygon", EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),
},
new EntityType("MovieRating")
{
new MemberProperty("Id", EdmDataTypes.Int32) { IsPrimaryKey = true },
new MemberProperty("Rating", DataTypes.ComplexType.WithDefinition("Rating")),
new MemberProperty("IsCreatedByCustomer", EdmDataTypes.Boolean),
new NavigationProperty("Movie", "MovieRating_Movie", "MovieRating", "Movie"),
},
new EntityType("Actor")
{
new MemberProperty("Id", EdmDataTypes.Int32) { IsPrimaryKey = true },
new MemberProperty("FirstName", EdmDataTypes.String()),
new MemberProperty("LastName", EdmDataTypes.String()),
new MemberProperty("Age", EdmDataTypes.Int32),
new MemberProperty("IsAwardWinner", EdmDataTypes.Boolean),
new MemberProperty("ContactDetails", DataTypes.ComplexType.WithName("ContactDetails")),
new MemberProperty("PrimaryPhoneNumber", DataTypes.ComplexType.WithName("Phone")),
new MemberProperty("AdditionalPhoneNumbers", DataTypes.CollectionOfComplex("Phone")),
new MemberProperty("AlternativeNames", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
new NavigationProperty("Movies", "Movies_Actors", "Actors", "Movies"),
},
new EntityType("Producer")
{
new MemberProperty("Id", EdmDataTypes.Int32) { IsPrimaryKey = true },
new MemberProperty("FirstName", EdmDataTypes.String()),
new MemberProperty("LastName", EdmDataTypes.String()),
new MemberProperty("Toggle", EdmDataTypes.Boolean),
},
new EntityType("ExecutiveProducer")
{
BaseType = "Producer"
},
new EntityType("ActorMovieRating")
//.........这里部分代码省略.........
示例12: BuildTestModel
/// <summary>
/// Build a test model shared across several tests.
/// </summary>
/// <returns>Returns the test model.</returns>
public static EntityModelSchema BuildTestModel()
{
// The metadata model
EntityModelSchema model = new EntityModelSchema().MinimumVersion(ODataVersion.V4);
ComplexType addressType = model.ComplexType("Address")
.Property("Street", EdmDataTypes.String().Nullable())
.Property("Zip", EdmDataTypes.Int32);
EntityType officeType = model.EntityType("OfficeType")
.KeyProperty("Id", EdmDataTypes.Int32)
.Property("Address", DataTypes.ComplexType.WithDefinition(addressType));
EntityType officeWithNumberType = model.EntityType("OfficeWithNumberType")
.WithBaseType(officeType)
.Property("Number", EdmDataTypes.Int32);
EntityType cityType = model.EntityType("CityType")
.KeyProperty("Id", EdmDataTypes.Int32)
.Property("Name", EdmDataTypes.String().Nullable())
.NavigationProperty("CityHall", officeType)
.NavigationProperty("DOL", officeType)
.NavigationProperty("PoliceStation", officeType, true)
.StreamProperty("Skyline")
.Property("MetroLanes", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String().Nullable()));
EntityType cityWithMapType = model.EntityType("CityWithMapType")
.WithBaseType(cityType)
.DefaultStream();
EntityType cityOpenType = model.EntityType("CityOpenType")
.WithBaseType(cityType)
.OpenType();
EntityType personType = model.EntityType("Person")
.KeyProperty("Id", EdmDataTypes.Int32);
personType = personType.NavigationProperty("Friend", personType);
EntityType employeeType = model.EntityType("Employee")
.WithBaseType(personType)
.Property("CompanyName", EdmDataTypes.String().Nullable());
EntityType managerType = model.EntityType("Manager")
.WithBaseType(employeeType)
.Property("Level", EdmDataTypes.Int32);
model.Add(new EntityContainer("DefaultContainer"));
model.EntitySet("Offices", officeType);
model.EntitySet("Cities", cityType);
model.EntitySet("Persons", personType);
model.Fixup();
// Fixed up models will have entity sets for all base entity types.
model.EntitySet("Employee", employeeType);
model.EntitySet("Manager", managerType);
EntityContainer container = model.EntityContainers.Single();
// NOTE: Function import parameters and return types must be nullable as per current CSDL spec
FunctionImport serviceOp = container.FunctionImport("ServiceOperation1")
.Parameter("a", EdmDataTypes.Int32.Nullable())
.Parameter("b", EdmDataTypes.String().Nullable())
.ReturnType(EdmDataTypes.Int32.Nullable());
container.FunctionImport("PrimitiveResultOperation")
.ReturnType(EdmDataTypes.Int32.Nullable());
container.FunctionImport("ComplexResultOperation")
.ReturnType(DataTypes.ComplexType.WithDefinition(addressType).Nullable());
container.FunctionImport("PrimitiveCollectionResultOperation")
.ReturnType(DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int32.Nullable()));
container.FunctionImport("ComplexCollectionResultOperation")
.ReturnType(DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(addressType).Nullable()));
// Overload with 0 Param
container.FunctionImport("FunctionImportWithOverload");
// Overload with 1 Param
container.FunctionImport("FunctionImportWithOverload")
.Parameter("p1", DataTypes.EntityType.WithDefinition(cityWithMapType));
// Overload with 2 Params
container.FunctionImport("FunctionImportWithOverload")
.Parameter("p1", DataTypes.EntityType.WithDefinition(cityType))
.Parameter("p2", EdmDataTypes.String().Nullable());
// Overload with 5 Params
container.FunctionImport("FunctionImportWithOverload")
.Parameter("p1", DataTypes.CollectionOfEntities(cityType))
.Parameter("p2", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String().Nullable()))
.Parameter("p3", EdmDataTypes.String().Nullable())
.Parameter("p4", DataTypes.ComplexType.WithDefinition(addressType).Nullable())
.Parameter("p5", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(addressType).Nullable()));
return model;
//.........这里部分代码省略.........
示例13: AddContainer
protected EntityContainer AddContainer(EntityModelSchema schema, string namespaceName)
{
EntityContainer container = new EntityContainer("TestContainer");
schema.Add(container);
new ApplyDefaultNamespaceFixup(namespaceName).Fixup(schema);
new ResolveReferencesFixup().Fixup(schema);
this.PrimitiveTypeResolver.ResolveProviderTypes(schema, this.EdmDataTypeResolver);
return container;
}
示例14: BuildTestMetadata
public static IEdmModel BuildTestMetadata(IEntityModelPrimitiveTypeResolver primitiveTypeResolver, IDataServiceProviderFactory provider)
{
var schema = new EntityModelSchema()
{
new ComplexType("TestNS","Address")
{
new MemberProperty("City", DataTypes.String.Nullable()),
new MemberProperty("Zip", DataTypes.Integer),
new ClrTypeAnnotation(typeof(Address))
},
new EntityType("TestNS","Customer")
{
new MemberProperty("ID", DataTypes.Integer){IsPrimaryKey=true},
new MemberProperty("Name", DataTypes.String.Nullable()),
new MemberProperty("Emails", DataTypes.CollectionType.WithElementDataType(DataTypes.String.Nullable())),
new MemberProperty("Address", DataTypes.ComplexType.WithName("TestNS","Address")),
new ClrTypeAnnotation(typeof(Customer))
},
new EntityType("TestNS","MultiKey")
{
new MemberProperty("KeyB", DataTypes.FloatingPoint){IsPrimaryKey=true},
new MemberProperty("KeyA", DataTypes.String.Nullable()){IsPrimaryKey=true},
new MemberProperty("Keya", DataTypes.Integer){IsPrimaryKey=true},
new MemberProperty("NonKey", DataTypes.String.Nullable()),
new ClrTypeAnnotation(typeof(MultiKey))
},
new EntityType("TestNS","TypeWithPrimitiveProperties")
{
new MemberProperty("ID", DataTypes.Integer){ IsPrimaryKey=true},
new MemberProperty("StringProperty", DataTypes.String.Nullable()),
new MemberProperty("BoolProperty", DataTypes.Boolean),
new MemberProperty("NullableBoolProperty", DataTypes.Boolean.Nullable()),
new MemberProperty("ByteProperty", EdmDataTypes.Byte),
new MemberProperty("NullableByteProperty", EdmDataTypes.Byte.Nullable()),
new MemberProperty("DateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true)),
new MemberProperty("NullableDateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()),
new MemberProperty("DecimalProperty", EdmDataTypes.Decimal()),
new MemberProperty("NullableDecimalProperty", EdmDataTypes.Decimal().Nullable()),
new MemberProperty("DoubleProperty", EdmDataTypes.Double),
new MemberProperty("NullableDoubleProperty", EdmDataTypes.Double.Nullable()),
new MemberProperty("GuidProperty", DataTypes.Guid),
new MemberProperty("NullableGuidProperty", DataTypes.Guid.Nullable()),
new MemberProperty("Int16Property", EdmDataTypes.Int16),
new MemberProperty("NullableInt16Property", EdmDataTypes.Int16.Nullable()),
new MemberProperty("Int32Property", DataTypes.Integer),
new MemberProperty("NullableInt32Property", DataTypes.Integer.Nullable()),
new MemberProperty("Int64Property", EdmDataTypes.Int64),
new MemberProperty("NullableInt64Property", EdmDataTypes.Int64.Nullable()),
new MemberProperty("SByteProperty", EdmDataTypes.SByte),
new MemberProperty("NullableSByteProperty", EdmDataTypes.SByte.Nullable()),
new MemberProperty("SingleProperty", EdmDataTypes.Single),
new MemberProperty("NullableSingleProperty", EdmDataTypes.Single.Nullable()),
new MemberProperty("BinaryProperty", DataTypes.Binary.Nullable()),
new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties))
}
};
List<FunctionParameter> defaultParameters = new List<FunctionParameter>()
{
new FunctionParameter("soParam", DataTypes.Integer)
};
EntitySet customersSet = new EntitySet("Customers", "Customer");
EntityContainer container = new EntityContainer("BinderTestMetadata")
{
customersSet,
new EntitySet("MultiKeys", "MultiKey"),
new EntitySet("TypesWithPrimitiveProperties","TypeWithPrimitiveProperties")
};
schema.Add(container);
EntityDataType customerType = DataTypes.EntityType.WithName("TestNS", "Customer");
EntityDataType multiKeyType = DataTypes.EntityType.WithName("TestNS", "MultiKey");
EntityDataType entityTypeWithPrimitiveProperties = DataTypes.EntityType.WithName("TestNS", "TypeWithPrimitiveProperties");
ComplexDataType addressType = DataTypes.ComplexType.WithName("TestNS", "Address");
addressType.Definition.Add(new ClrTypeAnnotation(typeof(Address)));
customerType.Definition.Add(new ClrTypeAnnotation(typeof(Customer)));
multiKeyType.Definition.Add(new ClrTypeAnnotation(typeof(MultiKey)));
entityTypeWithPrimitiveProperties.Definition.Add(new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties)));
//container.Add(CreateServiceOperation("VoidServiceOperation", defaultParameters, null, ODataServiceOperationResultKind.Void));
//container.Add(CreateServiceOperation("DirectValuePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.DirectValue));
//container.Add(CreateServiceOperation("DirectValueComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.DirectValue));
//container.Add(CreateServiceOperation("DirectValueEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.DirectValue));
//container.Add(CreateServiceOperation("EnumerationPrimitiveServiceOperation", defaultParameters, DataTypes.CollectionType.WithElementDataType(DataTypes.Integer), ODataServiceOperationResultKind.Enumeration));
//container.Add(CreateServiceOperation("EnumerationComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.Enumeration));
//container.Add(CreateServiceOperation("EnumerationEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.Enumeration));
//container.Add(CreateServiceOperation("QuerySinglePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithSingleResult));
//container.Add(CreateServiceOperation("QuerySingleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithSingleResult));
//container.Add(CreateServiceOperation("QuerySingleEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.QueryWithSingleResult));
//container.Add(CreateServiceOperation("QueryMultiplePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithMultipleResults));
//container.Add(CreateServiceOperation("QueryMultipleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithMultipleResults));
//container.Add(CreateServiceOperation("QueryMultipleEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));
//container.Add(CreateServiceOperation("ServiceOperationWithNoParameters", new List<FunctionParameter>(), DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));
//.........这里部分代码省略.........
示例15: GenerateModel
//.........这里部分代码省略.........
},
new EntityContainer("KatmaiTypeContainer")
{
new DataServiceConfigurationAnnotation()
{
UseVerboseErrors = true,
},
new DataServiceBehaviorAnnotation()
{
MaxProtocolVersion = DataServiceProtocolVersion.V4,
},
new EntitySet("DateTimeOffsets", "KatmaiEntity_DTO")
{
new PageSizeAnnotation() { PageSize = 3 },
},
new EntitySet("TimeSpans", "KatmaiEntity_TS")
{
new PageSizeAnnotation() { PageSize = 7 },
},
new EntitySet("KatmaiLinks", "KatmaiLink"),
new AssociationSet("KatmaiLinks_DTO")
{
AssociationType = "KatmaiLink_DTO",
Ends =
{
new AssociationSetEnd("Link", "KatmaiLinks"),
new AssociationSetEnd("DTO", "DateTimeOffsets"),
}
},
new AssociationSet("KatmaiLinks_TS")
{
AssociationType = "KatmaiLink_TS",
Ends =
{
new AssociationSetEnd("Link", "KatmaiLinks"),
new AssociationSetEnd("TS", "TimeSpans"),
}
},
new EntitySet("Calendars", "Calendar"),
new EntitySet("People", "Person"),
new EntitySet("Footraces", "Footrace"),
new EntitySet("FootraceTimes", "FootraceTime"),
new AssociationSet("People_Calendars")
{
AssociationType = "Person_Calendar",
Ends =
{
new AssociationSetEnd("Person", "People"),
new AssociationSetEnd("Calendar", "Calendars"),
}
},
new AssociationSet("People_Times")
{
AssociationType = "Person_Time",
Ends =
{
new AssociationSetEnd("Person", "People"),
new AssociationSetEnd("Time", "FootraceTimes"),
}
},
new AssociationSet("Footraces_Times")
{
AssociationType = "Footrace_Time",
Ends =
{
new AssociationSetEnd("Footrace", "Footraces"),
new AssociationSetEnd("Time", "FootraceTimes"),
}
},
}
};
// TODO: re-enable when product bug for service ops with type segments are fixed
////new AddRootServiceOperationsFixup().Fixup(model);
model.Add(CreateSimpleServiceOperation("GetDateTimeOffset", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
model.Add(CreateSimpleServiceOperation("GetNullableDateTimeOffset", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
model.Add(CreateSimpleServiceOperation("GetTimeSpan", DataTypes.TimeOfDay.NotNullable()));
model.Add(CreateSimpleServiceOperation("GetNullableTimeSpan", DataTypes.TimeOfDay.Nullable()));
model.Add(CreateCollectionServiceOperation("GetDateTimeOffsets", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
model.Add(CreateCollectionServiceOperation("GetNullableDateTimeOffsets", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
model.Add(CreateCollectionServiceOperation("GetTimeSpans", DataTypes.TimeOfDay.NotNullable()));
model.Add(CreateCollectionServiceOperation("GetNullableTimeSpans", DataTypes.TimeOfDay.Nullable()));
model.Add(CreateSingleEntityServiceOperation("GetFirstDTOEntityGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "Published", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
model.Add(CreateSingleEntityServiceOperation("GetFirstNullableDTOEntityGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "ETag", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
model.Add(CreateSingleEntityServiceOperation("GetFirstTSEntityGreaterThan", "TimeSpans", "KatmaiEntity_TS", "Title", DataTypes.TimeOfDay.NotNullable()));
model.Add(CreateSingleEntityServiceOperation("GetFirstNullableTSEntityGreaterThan", "TimeSpans", "KatmaiEntity_TS", "ETag", DataTypes.TimeOfDay.Nullable()));
model.Add(CreateMultipleEntityServiceOperation("GetDTOEntitiesGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "Published", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
model.Add(CreateMultipleEntityServiceOperation("GetNullableDTOEntitiesGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "ETag", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
model.Add(CreateMultipleEntityServiceOperation("GetTSEntitiesGreaterThan", "TimeSpans", "KatmaiEntity_TS", "Title", DataTypes.TimeOfDay.NotNullable()));
model.Add(CreateMultipleEntityServiceOperation("GetNullableTSEntitiesGreaterThan", "TimeSpans", "KatmaiEntity_TS", "ETag", DataTypes.TimeOfDay.Nullable()));
new ResolveReferencesFixup().Fixup(model);
new ApplyDefaultNamespaceFixup("KatmaiTypes").Fixup(model);
return model;
}