本文整理汇总了C#中IEdmModel.EntityTypes方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmModel.EntityTypes方法的具体用法?C# IEdmModel.EntityTypes怎么用?C# IEdmModel.EntityTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmModel
的用法示例。
在下文中一共展示了IEdmModel.EntityTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePayloadElement
private static ODataPayloadElement CreatePayloadElement(IEdmModel model, ODataPayloadKind payloadKind, ReaderTestConfiguration testConfig)
{
IEdmEntitySet citySet = model.EntityContainer.FindEntitySet("Cities");
IEdmEntityType cityType = model.EntityTypes().Single(e => e.Name == "CityType");
IEdmProperty cityNameProperty = cityType.Properties().Single(e => e.Name == "Name");
IEdmNavigationProperty policeStationNavProp = cityType.NavigationProperties().Single(e => e.Name == "PoliceStation");
IEdmOperationImport primitiveCollectionResultOperation = model.EntityContainer.FindOperationImports("PrimitiveCollectionResultOperation").Single();
IEdmOperationImport serviceOp1 = model.EntityContainer.FindOperationImports("ServiceOperation1").Single();
bool isRequest = testConfig.IsRequest;
bool isJsonLightRequest = isRequest && testConfig.Format == ODataFormat.Json;
switch (payloadKind)
{
case ODataPayloadKind.Feed:
{
return PayloadBuilder.EntitySet().WithTypeAnnotation(cityType).ExpectedEntityType(cityType, citySet);
}
case ODataPayloadKind.Entry:
{
return PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).WithTypeAnnotation(cityType).ExpectedEntityType(cityType, citySet);
}
case ODataPayloadKind.Property:
return PayloadBuilder.PrimitiveProperty(isJsonLightRequest ? string.Empty : null, "SomeCityValue").ExpectedProperty(cityType, "Name");
case ODataPayloadKind.EntityReferenceLink:
return PayloadBuilder.DeferredLink("http://odata.org/entityreferencelink").ExpectedNavigationProperty(citySet, cityType, "PoliceStation");
case ODataPayloadKind.EntityReferenceLinks:
return PayloadBuilder.LinkCollection().Item(PayloadBuilder.DeferredLink("http://odata.org/entityreferencelink")).ExpectedNavigationProperty((EdmEntitySet)citySet, (EdmEntityType)cityType, "CityHall");
case ODataPayloadKind.Value:
return PayloadBuilder.PrimitiveValue("PrimitiveValue");
case ODataPayloadKind.BinaryValue:
return PayloadBuilder.PrimitiveValue(new byte[] { 0, 0, 1, 1 });
case ODataPayloadKind.Collection:
return PayloadBuilder.PrimitiveCollection().CollectionName(null).ExpectedFunctionImport((EdmOperationImport)primitiveCollectionResultOperation);
case ODataPayloadKind.ServiceDocument:
Debug.Assert(!isRequest, "Not supported in requests.");
return new ServiceDocumentInstance().Workspace(PayloadBuilder.Workspace());
case ODataPayloadKind.MetadataDocument:
Debug.Assert(!isRequest, "Not supported in requests.");
throw new NotImplementedException();
case ODataPayloadKind.Error:
Debug.Assert(!isRequest, "Not supported in requests.");
return PayloadBuilder.Error("ErrorCode");
case ODataPayloadKind.Parameter:
// build parameter payload based on model definition
var parameterPayload = new ComplexInstance(null, false);
ODataPayloadElement a = PayloadBuilder.PrimitiveValue(123).WithTypeAnnotation(EdmCoreModel.Instance.GetInt32(false));
ODataPayloadElement b = PayloadBuilder.PrimitiveValue("stringvalue").WithTypeAnnotation(EdmCoreModel.Instance.GetString(false));
PrimitiveProperty parametera = new PrimitiveProperty("a", "Edm.Integer", ((PrimitiveValue)a).ClrValue);
PrimitiveProperty parameterb = new PrimitiveProperty("b", "Edm.String", ((PrimitiveValue)b).ClrValue);
parameterPayload.Add(parametera);
parameterPayload.Add(parameterb);
parameterPayload.ExpectedFunctionImport((EdmOperationImport)serviceOp1);
return parameterPayload;
case ODataPayloadKind.Unsupported: // fall through
default:
throw new NotSupportedException();
}
}
示例2: CreateFeedValidatorDescriptors
private IEnumerable<PayloadWriterTestDescriptor<ODataPayloadElement>> CreateFeedValidatorDescriptors(IEdmModel model)
{
var cityType = model.EntityTypes().Single(type => type.FullName() == "TestModel.CityType");
var personType = model.EntityTypes().Single(type => type.FullName() == "TestModel.Person");
var employeeType = model.EntityTypes().Single(type => type.FullName() == "TestModel.Employee");
var testCases = new[]
{
new
{
Description = "Homogenous collection (no inheritance)",
Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithDefaultAtomIDAnnotation().WithTypeAnnotation(personType)
.Append(PayloadBuilder.Entity("TestModel.Person")
.PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
.Append(PayloadBuilder.Entity("TestModel.Person")
.PrimitiveProperty("Id", 2).WithTypeAnnotation(personType)),
ExpectedException = (ExpectedException)null,
Model = model
},
new
{
Description = "Homogenous collection (inheritance, base type first)",
Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithDefaultAtomIDAnnotation().WithTypeAnnotation(personType)
.Append(PayloadBuilder.Entity("TestModel.Person")
.PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
.Append(PayloadBuilder.Entity("TestModel.Employee")
.PrimitiveProperty("Id", 2).WithTypeAnnotation(employeeType)),
ExpectedException = (ExpectedException)null,
Model = model
},
new
{
Description = "Homogenous collection (inheritance, derived type first)",
Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithDefaultAtomIDAnnotation().WithTypeAnnotation(personType)
.Append(PayloadBuilder.Entity("TestModel.Employee")
.PrimitiveProperty("Id", 1).WithTypeAnnotation(employeeType))
.Append(PayloadBuilder.Entity("TestModel.Person")
.PrimitiveProperty("Id", 2).WithTypeAnnotation(personType)),
ExpectedException = (ExpectedException)null,
Model = model
},
new
{
Description = "Heterogeneous collection",
Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithDefaultAtomIDAnnotation().WithTypeAnnotation(personType)
.Append(PayloadBuilder.Entity("TestModel.Person")
.PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
.Append(PayloadBuilder.Entity("TestModel.CityType")
.PrimitiveProperty("Id", 2).WithTypeAnnotation(cityType)),
ExpectedException = ODataExpectedExceptions.ODataException("FeedWithoutExpectedTypeValidator_IncompatibleTypes", "TestModel.CityType", "TestModel.Person"),
Model = model
},
new
{
Description = "Heterogeneous collection (no model)",
Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithDefaultAtomIDAnnotation()
.Append(PayloadBuilder.Entity("TestModel.Person")
.PrimitiveProperty("Id", 1))
.Append(PayloadBuilder.Entity("TestModel.CityType")
.PrimitiveProperty("Id", 2)),
ExpectedException = (ExpectedException)null,
Model = (IEdmModel)null
},
};
// Create the tests for a top-level feed
return testCases.Select(testCase =>
new PayloadWriterTestDescriptor<ODataPayloadElement>(this.Settings, testCase.Feed)
{
DebugDescription = testCase.Description,
Model = testCase.Model,
PayloadDescriptor = new PayloadTestDescriptor()
{
DebugDescription = testCase.Description,
PayloadElement = testCase.Feed,
PayloadEdmModel = testCase.Model,
SkipTestConfiguration = tc => testCase.Model == null && tc.Format == ODataFormat.Json,
},
ExpectedResultCallback = (tc) =>
{
return new PayloadWriterTestExpectedResults(this.ExpectedResultSettings)
{
ExpectedPayload = testCase.Feed,
ExpectedException2 = testCase.ExpectedException,
};
}
});
}