本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityContainer.AddSingleton方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityContainer.AddSingleton方法的具体用法?C# EdmEntityContainer.AddSingleton怎么用?C# EdmEntityContainer.AddSingleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmEntityContainer
的用法示例。
在下文中一共展示了EdmEntityContainer.AddSingleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTestModel
private IEdmModel CreateTestModel()
{
EdmModel model = new EdmModel();
EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default");
model.AddElement(defaultContainer);
var productType = new EdmEntityType("TestModel", "Product");
EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false));
productType.AddProperty(idProperty);
productType.AddKeys(idProperty);
productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true)));
model.AddElement(productType);
var customerType = new EdmEntityType("TestModel", "Customer");
idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false));
customerType.AddProperty(idProperty);
customerType.AddKeys(idProperty);
customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true)));
model.AddElement(productType);
defaultContainer.AddEntitySet("Products", productType);
defaultContainer.AddEntitySet("Customers", customerType);
defaultContainer.AddSingleton("SingleProduct", productType);
defaultContainer.AddSingleton("SingleCustomer", customerType);
EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/);
model.AddElement(action);
defaultContainer.AddActionImport("SimpleActionImport", action);
EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1);
EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/);
return model;
}
示例2: GetModel
//.........这里部分代码省略.........
// EntitySet: Accounts
var accounts = container.AddEntitySet("Accounts", account);
var paymentInstruments = accounts.FindNavigationTarget(myPaymentInstruments) as EdmNavigationSource;
Assert.NotNull(paymentInstruments);
paymentInstruments.AddNavigationTarget(billingAddresses, addresses);
// EntityType: Person
var person = new EdmEntityType("ns", "Person");
var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
person.AddKeys(personId);
var myAccounts = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyAccounts",
Target = account,
TargetMultiplicity = EdmMultiplicity.Many
});
var myPermanentAccount = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyPermanentAccount",
Target = account,
TargetMultiplicity = EdmMultiplicity.One
});
var myLatestAccount = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyLatestAccount",
Target = account,
TargetMultiplicity = EdmMultiplicity.One
});
person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyAddresses",
Target = address,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
model.AddElement(person);
// EntityType: Benefit
var benefit = new EdmEntityType("ns", "Benefit");
var benefitId = benefit.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
benefit.AddKeys(benefitId);
model.AddElement(benefit);
// EntityType: SpecialPerson
var specialPerson = new EdmEntityType("ns", "SpecialPerson", person);
specialPerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "Benefits",
Target = benefit,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
model.AddElement(specialPerson);
// EntityType: VIP
var vip = new EdmEntityType("ns", "VIP", specialPerson);
vip.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyBenefits",
Target = benefit,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
model.AddElement(vip);
// EntitySet: People
var people = container.AddEntitySet("People", person);
people.AddNavigationTarget(myAccounts, accounts);
people.AddNavigationTarget(myLatestAccount, accounts);
// EntityType: Club
var club = new EdmEntityType("ns", "Club");
var clubId = club.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
club.AddKeys(clubId);
var members = club.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "Members",
Target = person,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
// EntityType: SeniorClub
var seniorClub = new EdmEntityType("ns", "SeniorClub", club);
model.AddElement(seniorClub);
// EntitySet: Clubs
var clubs = container.AddEntitySet("Clubs", club);
var membersInClub = clubs.FindNavigationTarget(members) as EdmNavigationSource;
membersInClub.AddNavigationTarget(myAccounts, accounts);
// Singleton: PermanentAccount
var permanentAccount = container.AddSingleton("PermanentAccount", account);
people.AddNavigationTarget(myPermanentAccount, permanentAccount);
_model = model;
return _model;
}
示例3: CustomersModelWithInheritance
//.........这里部分代码省略.........
orderLine.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
model.AddElement(orderLine);
EdmNavigationProperty orderLinesNavProp = myOrder.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo
{
Name = "OrderLines",
TargetMultiplicity = EdmMultiplicity.Many,
Target = orderLine,
ContainsTarget = true,
});
EdmNavigationProperty nonContainedOrderLinesNavProp = myOrder.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo
{
Name = "NonContainedOrderLines",
TargetMultiplicity = EdmMultiplicity.Many,
Target = orderLine,
ContainsTarget = false,
});
EdmAction tag = new EdmAction("NS", "tag", returnType: null, isBound: true, entitySetPathExpression: null);
tag.AddParameter("entity", new EdmEntityTypeReference(orderLine, false));
model.AddElement(tag);
// entity sets
EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance");
model.AddElement(container);
EdmEntitySet customers = container.AddEntitySet("Customers", customer);
EdmEntitySet orders = container.AddEntitySet("Orders", order);
EdmEntitySet myOrders = container.AddEntitySet("MyOrders", myOrder);
// singletons
EdmSingleton vipCustomer = container.AddSingleton("VipCustomer", customer);
EdmSingleton mary = container.AddSingleton("Mary", customer);
EdmSingleton rootOrder = container.AddSingleton("RootOrder", order);
// annotations
model.SetOptimisticConcurrencyAnnotation(customers, new[] { city });
// containment
IEdmContainedEntitySet orderLines = (IEdmContainedEntitySet)myOrders.FindNavigationTarget(orderLinesNavProp);
// no-containment
IEdmNavigationSource nonContainedOrderLines = myOrders.FindNavigationTarget(nonContainedOrderLinesNavProp);
// actions
EdmAction upgrade = new EdmAction("NS", "upgrade", returnType: null, isBound: true, entitySetPathExpression: null);
upgrade.AddParameter("entity", new EdmEntityTypeReference(customer, false));
model.AddElement(upgrade);
EdmAction specialUpgrade =
new EdmAction("NS", "specialUpgrade", returnType: null, isBound: true, entitySetPathExpression: null);
specialUpgrade.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
model.AddElement(specialUpgrade);
// actions bound to collection
EdmAction upgradeAll = new EdmAction("NS", "UpgradeAll", returnType: null, isBound: true, entitySetPathExpression: null);
upgradeAll.AddParameter("entityset",
new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false))));
model.AddElement(upgradeAll);
EdmAction upgradeSpecialAll = new EdmAction("NS", "UpgradeSpecialAll", returnType: null, isBound: true, entitySetPathExpression: null);
upgradeSpecialAll.AddParameter("entityset",
new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(specialCustomer, false))));
model.AddElement(upgradeSpecialAll);
示例4: TwoWayNavigationPropertyMultipleMappingInSingletonTest
public void TwoWayNavigationPropertyMultipleMappingInSingletonTest()
{
var model = new EdmModel();
var t3 = new EdmEntityType("Bunk", "T3");
var f31 = t3.AddStructuralProperty("F31", EdmCoreModel.Instance.GetString(false));
t3.AddKeys(f31);
model.AddElement(t3);
var t1 = new EdmEntityType("Bunk", "T1");
var f11 = t1.AddStructuralProperty("F11", EdmCoreModel.Instance.GetString(false));
t1.AddKeys(f11);
var p101 = t1.AddBidirectionalNavigation
(
new EdmNavigationPropertyInfo() { Name = "P101", Target = t3, TargetMultiplicity = EdmMultiplicity.One },
new EdmNavigationPropertyInfo() { Name = "P301", TargetMultiplicity = EdmMultiplicity.One }
);
model.AddElement(t1);
var c1 = new EdmEntityContainer("Bunk", "Gunk");
var E1a = c1.AddEntitySet("E1a", t1);
var E1b = c1.AddSingleton("E1b", t1);
var E3 = c1.AddSingleton("E3", t3);
E1a.AddNavigationTarget(p101, E3);
E1b.AddNavigationTarget(p101, E3);
E3.AddNavigationTarget(p101.Partner, E1a);
model.AddElement(c1);
var expectedErrors = new EdmLibTestErrors()
{
{ "(Microsoft.OData.Edm.Library.EdmSingleton)", EdmErrorCode.NavigationMappingMustBeBidirectional },
};
IEnumerable<EdmError> edmErrors;
model.Validate(out edmErrors);
this.CompareErrors(edmErrors, expectedErrors);
}
示例5: NavigationPropertyOfCollectionTypeTargetToSingleton
public static IEdmModel NavigationPropertyOfCollectionTypeTargetToSingleton()
{
var model = new EdmModel();
var person = new EdmEntityType("NS", "Person");
var personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
person.AddKeys(personId);
model.AddElement(person);
var address = new EdmEntityType("NS", "Address");
var addressId = address.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
address.AddKeys(addressId);
model.AddElement(address);
var personToAddress = EdmNavigationProperty.CreateNavigationPropertyWithPartner(
new EdmNavigationPropertyInfo() { Name = "Addresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many },
new EdmNavigationPropertyInfo() { Name = "Owner", Target = person, TargetMultiplicity = EdmMultiplicity.One});
person.AddProperty(personToAddress);
address.AddProperty(personToAddress.Partner);
var container = new EdmEntityContainer("NS", "Container");
model.AddElement(container);
var people = container.AddEntitySet("People", person);
var singleAddress = container.AddSingleton("SingleAddress", address);
people.AddNavigationTarget(personToAddress, singleAddress);
singleAddress.AddNavigationTarget(personToAddress.Partner, people);
return model;
}
示例6: GetEdmModel
//.........这里部分代码省略.........
var FullyQualifiedNamespaceContext = new EdmEntityContainer("Fully.Qualified.Namespace", "Context");
model.AddElement(FullyQualifiedNamespaceContext);
var FullyQualifiedNamespaceContextPeople = FullyQualifiedNamespaceContext.AddEntitySet("People", FullyQualifiedNamespacePerson);
var FullyQualifiedNamespaceContextDogs = FullyQualifiedNamespaceContext.AddEntitySet("Dogs", FullyQualifiedNamespaceDog);
var FullyQualifiedNamespaceContextLions = FullyQualifiedNamespaceContext.AddEntitySet("Lions", FullyQualifiedNamespaceLion);
var FullyQualifiedNamespaceContextPaintings = FullyQualifiedNamespaceContext.AddEntitySet("Paintings", FullyQualifiedNamespacePainting);
var FullyQualifiedNamespaceContextUsers = FullyQualifiedNamespaceContext.AddEntitySet("Users", FullyQualifiedNamespaceUserAccount);
var FullyQualifiedNamespaceContextPet1Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet1Set", FullyQualifiedNamespacePet1);
var FullyQualifiedNamespaceContextPet2Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet2Set", FullyQualifiedNamespacePet2);
var FullyQualifiedNamespaceContextPet3Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet3Set", FullyQualifiedNamespacePet3);
var FullyQualifiedNamespaceContextPet4Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet4Set", FullyQualifiedNamespacePet4);
var FullyQualifiedNamespaceContextPet5Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet5Set", FullyQualifiedNamespacePet5);
var FullyQualifiedNamespaceContextPet6Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet6Set", FullyQualifiedNamespacePet6);
var FullyQualifiedNamespaceContextChimera = FullyQualifiedNamespaceContext.AddEntitySet("Chimeras", FullyQualifiedNamespaceChimera);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyDog, FullyQualifiedNamespaceContextDogs);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyRelatedDogs, FullyQualifiedNamespaceContextDogs);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyLions, FullyQualifiedNamespaceContextLions);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPaintings, FullyQualifiedNamespaceContextPaintings);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyFavoritePainting, FullyQualifiedNamespaceContextPaintings);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceEmployee_PaintingsInOffice, FullyQualifiedNamespaceContextPaintings);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceEmployee_Manager, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceManager_DirectReports, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPet2Set, FullyQualifiedNamespaceContextPet2Set);
FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_MyPeople, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_FastestOwner, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_LionsISaw, FullyQualifiedNamespaceContextLions);
FullyQualifiedNamespaceContextLions.AddNavigationTarget(FullyQualifiedNamespaceLion_Friends, FullyQualifiedNamespaceContextLions);
FullyQualifiedNamespaceContextPaintings.AddNavigationTarget(FullyQualifiedNamespacePainting_Owner, FullyQualifiedNamespaceContextPeople);
// Add singleton
var FullQualifiedNamespaceSingletonBoss = FullyQualifiedNamespaceContext.AddSingleton("Boss", FullyQualifiedNamespacePerson);
FullQualifiedNamespaceSingletonBoss.AddNavigationTarget(FullyQualifiedNamespacePerson_MyDog, FullyQualifiedNamespaceContextDogs);
FullQualifiedNamespaceSingletonBoss.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPaintings, FullyQualifiedNamespaceContextPaintings);
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet1", FullyQualifiedNamespaceGetPet1Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet1Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet2", FullyQualifiedNamespaceGetPet2Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet2Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet3", FullyQualifiedNamespaceGetPet3Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet3Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet4", FullyQualifiedNamespaceGetPet4Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet4Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet5", FullyQualifiedNamespaceGetPet5Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet5Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet6", FullyQualifiedNamespaceGetPet6Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet6Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPetCount", FullyQualifiedNamespaceGetPetCountFunction, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet5Set));
FullyQualifiedNamespaceContext.AddFunctionImport("FindMyOwner", FullyQualifiedNamespaceFindMyOwnerFunction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("IsAddressGood", FullyQualifiedNamespaceIsAddressGoodFunction, null);
FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolPeople", FullyQualifiedNamespaceGetCoolPeopleAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolestPerson", FullyQualifiedNamespaceGetCoolestPersonAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolestPersonWithStyle", FullyQualifiedNamespaceGetCoolestPersonWithStyleAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("GetBestManager", FullyQualifiedNamespaceGetBestManagerAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddActionImport("GetNothing", FullyQualifiedNamespaceGetNothingAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeNumber", FullyQualifiedNamespaceGetSomeNumberAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeAddress", FullyQualifiedNamespaceGetSomeAddressAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeNumbers", FullyQualifiedNamespaceGetSomeNumbersAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeAddresses", FullyQualifiedNamespaceGetSomeAddressesAction);
示例7: CustomTermDemo
private static void CustomTermDemo()
{
Console.WriteLine("CustomTermDemo");
var model = new EdmModel();
var term = new EdmTerm("ns", "ErrorCodes",
new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))));
model.AddElement(term);
var entity1 = new EdmEntityType("ns", "entity1");
entity1.AddKeys(entity1.AddStructuralProperty("id", EdmPrimitiveTypeKind.Guid));
model.AddElement(entity1);
var container = new EdmEntityContainer("ns", "default");
model.AddElement(container);
var e1 = container.AddSingleton("E1", entity1);
var annotation = new EdmAnnotation(e1, term,
new EdmCollectionExpression(
new EdmStringConstant("Entity Not Found"),
new EdmStringConstant("Deleting link failed")));
model.AddVocabularyAnnotation(annotation);
ShowModel(model);
}
示例8: CastTests
public void CastTests(string path, string expectedEdmType)
{
// Arrange
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
var vehicle = new EdmEntityType("NS", "Vehicle");
var car = new EdmEntityType("NS", "Car", vehicle);
var motorcycle = new EdmEntityType("NS", "Motorcycle", vehicle);
model.AddElements(new IEdmSchemaElement[] { vehicle, car, motorcycle, container });
container.AddEntitySet("Vehicles", vehicle);
container.AddEntitySet("Cars", car);
container.AddEntitySet("Motorcycles", motorcycle);
container.AddSingleton("Contoso", vehicle);
// Act
ODataPath odataPath = _parser.Parse(model, path);
// Assert
Assert.NotNull(odataPath);
Assert.Equal(expectedEdmType, odataPath.EdmType.ToTraceString());
}
示例9: CraftModel
public CraftModel()
{
model = new EdmModel();
var address = new EdmComplexType("NS", "Address");
model.AddElement(address);
var mail = new EdmEntityType("NS", "Mail");
var mailId = mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
mail.AddKeys(mailId);
model.AddElement(mail);
var person = new EdmEntityType("NS", "Person");
model.AddElement(person);
var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
person.AddKeys(personId);
person.AddStructuralProperty("Addr", new EdmComplexTypeReference(address, /*Nullable*/false));
MailBox = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
ContainsTarget = true,
Name = "Mails",
TargetMultiplicity = EdmMultiplicity.Many,
Target = mail,
});
var container = new EdmEntityContainer("NS", "DefaultContainer");
model.AddElement(container);
MyLogin = container.AddSingleton("MyLogin", person);
}
示例10: BuildTestModel
/// <summary>
/// Build a test model shared across several tests.
/// </summary>
/// <returns>Returns the test model.</returns>
public static EdmModel BuildTestModel()
{
// The metadata model
var model = new EdmModel();
var addressType = new EdmComplexType(DefaultNamespaceName, "Address");
addressType.AddStructuralProperty("Street", StringNullableTypeRef);
addressType.AddStructuralProperty("Zip", Int32TypeRef);
addressType.AddStructuralProperty("SubAddress", new EdmComplexTypeReference(addressType, isNullable: false));
model.AddElement(addressType);
var officeType = new EdmEntityType(DefaultNamespaceName, "OfficeType");
officeType.AddKeys(officeType.AddStructuralProperty("Id", Int32TypeRef));
officeType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, isNullable: false));
model.AddElement(officeType);
var officeWithNumberType = new EdmEntityType(DefaultNamespaceName, "OfficeWithNumberType", officeType);
officeWithNumberType.AddStructuralProperty("Number", Int32TypeRef);
model.AddElement(officeWithNumberType);
var cityType = new EdmEntityType(DefaultNamespaceName, "CityType");
cityType.AddKeys(cityType.AddStructuralProperty("Id", Int32TypeRef));
cityType.AddStructuralProperty("Name", StringNullableTypeRef);
cityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CityHall", Target = officeType, TargetMultiplicity = EdmMultiplicity.Many });
cityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DOL", Target = officeType, TargetMultiplicity = EdmMultiplicity.Many });
cityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "PoliceStation", Target = officeType, TargetMultiplicity = EdmMultiplicity.One });
cityType.AddStructuralProperty("Skyline", EdmPrimitiveTypeKind.Stream, isNullable: false);
cityType.AddStructuralProperty("MetroLanes", EdmCoreModel.GetCollection(StringNullableTypeRef));
model.AddElement(cityType);
var metropolitanCityType = new EdmEntityType(DefaultNamespaceName, "MetropolitanCityType", cityType);
metropolitanCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ContainedOffice", Target = officeType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true });
officeType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ContainedCity", Target = metropolitanCityType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true });
model.AddElement(metropolitanCityType);
var cityWithMapType = new EdmEntityType(DefaultNamespaceName, "CityWithMapType", cityType, false, false, true);
model.AddElement(cityWithMapType);
var cityOpenType = new EdmEntityType(DefaultNamespaceName, "CityOpenType", cityType, isAbstract: false, isOpen: true);
model.AddElement(cityOpenType);
var personType = new EdmEntityType(DefaultNamespaceName, "Person");
personType.AddKeys(personType.AddStructuralProperty("Id", Int32TypeRef));
personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Friend", Target = personType, TargetMultiplicity = EdmMultiplicity.Many });
model.AddElement(personType);
var employeeType = new EdmEntityType(DefaultNamespaceName, "Employee", personType);
employeeType.AddStructuralProperty("CompanyName", StringNullableTypeRef);
model.AddElement(employeeType);
var managerType = new EdmEntityType(DefaultNamespaceName, "Manager", employeeType);
managerType.AddStructuralProperty("Level", Int32TypeRef);
model.AddElement(managerType);
var container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer");
model.AddElement(container);
container.AddEntitySet("Offices", officeType);
container.AddEntitySet("Cities", cityType);
container.AddEntitySet("MetropolitanCities", metropolitanCityType);
container.AddEntitySet("Persons", personType);
container.AddEntitySet("Employee", employeeType);
container.AddEntitySet("Manager", managerType);
container.AddSingleton("Boss", personType);
// Fixup will set DefaultContainer\TopLevelEntitySet\AssociationSet
model.Fixup();
// NOTE: Function import parameters and return types must be nullable as per current CSDL spec
var serviceOp = container.AddFunctionAndFunctionImport(model, "ServiceOperation1", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/);
serviceOp.Function.AsEdmFunction().AddParameter("a", Int32NullableTypeRef);
serviceOp.Function.AsEdmFunction().AddParameter("b", StringNullableTypeRef);
container.AddFunctionAndFunctionImport(model, "PrimitiveResultOperation", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/);
container.AddFunctionAndFunctionImport(model, "ComplexResultOperation", new EdmComplexTypeReference(addressType, isNullable: true), null, false /*isComposable*/, false /*isBound*/);
container.AddFunctionAndFunctionImport(model, "PrimitiveCollectionResultOperation", EdmCoreModel.GetCollection(Int32NullableTypeRef), null, false /*isComposable*/, false /*isBound*/);
container.AddFunctionAndFunctionImport(model, "ComplexCollectionResultOperation", EdmCoreModel.GetCollection(new EdmComplexTypeReference(addressType, isNullable: true)), null, false /*isComposable*/, false /*isBound*/);
// Overload with 0 Param
container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/);
// Overload with 1 Param
var overloadWithOneParam = container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/);
overloadWithOneParam.Function.AsEdmFunction().AddParameter("p1", new EdmEntityTypeReference(cityWithMapType, isNullable: true));
// Overload with 2 Params
var overloadWithTwoParams = container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/);
overloadWithTwoParams.Function.AsEdmFunction().AddParameter("p1", new EdmEntityTypeReference(cityType, isNullable: true));
overloadWithTwoParams.Function.AsEdmFunction().AddParameter("p2", StringNullableTypeRef);
// Overload with 5 Params
var overloadWithFiveParams = container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/);
overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p1", EdmCoreModel.GetCollection(new EdmEntityTypeReference(cityType, isNullable: true)));
overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p2", EdmCoreModel.GetCollection(StringNullableTypeRef));
overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p3", StringNullableTypeRef);
overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p4", new EdmComplexTypeReference(addressType, isNullable: true));
//.........这里部分代码省略.........
示例11: TestCoreDescriptionAnnotation
public void TestCoreDescriptionAnnotation()
{
EdmModel model = new EdmModel();
const string personTypeDescription = "this is person type.";
const string personTypeLongDescription = "this is person type, but with a longer description.";
const string overwritePersonDescription = "this is overwritten person type.";
const string propertyIdDescription = "this is property Id.";
const string structuralPropertyDescription = "this is structural property.";
const string stringTermDescription = "this is string term.";
const string entitySetDescription = "this is entitySet.";
const string singletonDescription = "this is singleton.";
EdmEntityContainer container = new EdmEntityContainer("Ns", "Container");
var personType = new EdmEntityType("Ns", "Person");
var propertyId = personType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
personType.AddKeys(propertyId);
var structuralProperty = personType.AddStructuralProperty("Concurrency", EdmCoreModel.Instance.GetInt32(true));
model.AddElement(personType);
var entitySet = container.AddEntitySet("People", personType);
var driverSet = container.AddEntitySet("Drivers", personType);
var stringTerm = new EdmTerm("Ns", "HomeAddress", EdmCoreModel.Instance.GetString(true));
model.AddElement(stringTerm);
var singleton = container.AddSingleton("Boss", personType);
model.AddElement(container);
model.SetDescriptionAnnotation(personType, personTypeDescription);
model.SetDescriptionAnnotation(personType, overwritePersonDescription);
model.SetLongDescriptionAnnotation(personType, personTypeLongDescription);
model.SetDescriptionAnnotation(structuralProperty, structuralPropertyDescription);
model.SetDescriptionAnnotation(propertyId, propertyIdDescription);
model.SetDescriptionAnnotation(stringTerm, stringTermDescription);
model.SetDescriptionAnnotation(entitySet, entitySetDescription);
model.SetDescriptionAnnotation(singleton, singletonDescription);
Assert.AreEqual(overwritePersonDescription, model.GetDescriptionAnnotation(personType));
Assert.AreEqual(personTypeLongDescription, model.GetLongDescriptionAnnotation(personType));
Assert.AreEqual(structuralPropertyDescription, model.GetDescriptionAnnotation(structuralProperty));
Assert.AreEqual(propertyIdDescription, model.GetDescriptionAnnotation(propertyId));
Assert.AreEqual(stringTermDescription, model.GetDescriptionAnnotation(stringTerm));
Assert.AreEqual(entitySetDescription, model.GetDescriptionAnnotation(entitySet));
Assert.AreEqual(singletonDescription, model.GetDescriptionAnnotation(singleton));
Assert.IsNull(model.GetDescriptionAnnotation(driverSet));
const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""Ns"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<EntityType Name=""Person"">
<Key>
<PropertyRef Name=""Id"" />
</Key>
<Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is property Id."" />
</Property>
<Property Name=""Concurrency"" Type=""Edm.Int32"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is structural property."" />
</Property>
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is overwritten person type."" />
<Annotation Term=""Org.OData.Core.V1.LongDescription"" String=""this is person type, but with a longer description."" />
</EntityType>
<Term Name=""HomeAddress"" Type=""Edm.String"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is string term."" />
</Term>
<EntityContainer Name=""Container"">
<EntitySet Name=""People"" EntityType=""Ns.Person"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is entitySet."" />
</EntitySet>
<EntitySet Name=""Drivers"" EntityType=""Ns.Person"" />
<Singleton Name=""Boss"" Type=""Ns.Person"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is singleton."" />
</Singleton>
</EntityContainer>
</Schema>";
IEnumerable<EdmError> errors;
StringWriter sw = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = System.Text.Encoding.UTF8;
XmlWriter xw = XmlWriter.Create(sw, settings);
model.TryWriteCsdl(xw, out errors);
xw.Flush();
xw.Close();
var actual = sw.ToString();
Assert.AreEqual(expected, actual);
IEdmModel parsedModel;
IEnumerable<EdmError> errs;
bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(expected)) }, out parsedModel, out errs);
Assert.IsTrue(parsed, "parsed");
Assert.IsTrue(!errors.Any(), "No errors");
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(personType));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(structuralProperty));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(propertyId));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(stringTerm));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(entitySet));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(singleton));
//.........这里部分代码省略.........
示例12: SingletonInaccessibleEntityType
public static IEdmModel SingletonInaccessibleEntityType()
{
var model = new EdmModel();
var entity = new EdmEntityType("Foo", "Bar");
var id = new EdmStructuralProperty(entity, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
entity.AddKeys(id);
var entityContainer = new EdmEntityContainer("Foo", "Container");
entityContainer.AddSingleton("Baz", entity);
model.AddElement(entityContainer);
return model;
}
示例13: CustomersModelWithInheritance
public CustomersModelWithInheritance()
{
EdmModel model = new EdmModel();
// Enum type simpleEnum
EdmEnumType simpleEnum = new EdmEnumType("NS", "SimpleEnum");
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "First", new EdmIntegerConstant(0)));
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Second", new EdmIntegerConstant(1)));
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Third", new EdmIntegerConstant(2)));
model.AddElement(simpleEnum);
// complex type address
EdmComplexType address = new EdmComplexType("NS", "Address");
address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
address.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
address.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String);
address.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
model.AddElement(address);
// entity type customer
EdmEntityType customer = new EdmEntityType("NS", "Customer");
customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
IEdmProperty customerName = customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
customer.AddStructuralProperty("SimpleEnum", simpleEnum.ToEdmTypeReference(isNullable: false));
customer.AddStructuralProperty("Address", new EdmComplexTypeReference(address, isNullable: true));
IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive(
EdmPrimitiveTypeKind.String,
isNullable: true);
customer.AddStructuralProperty(
"City",
primitiveTypeReference,
defaultValue: null,
concurrencyMode: EdmConcurrencyMode.Fixed);
model.AddElement(customer);
// derived entity type special customer
EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer);
specialCustomer.AddStructuralProperty("SpecialCustomerProperty", EdmPrimitiveTypeKind.Guid);
specialCustomer.AddStructuralProperty("SpecialAddress", new EdmComplexTypeReference(address, isNullable: true));
model.AddElement(specialCustomer);
// entity type order
EdmEntityType order = new EdmEntityType("NS", "Order");
order.AddKeys(order.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
order.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32);
model.AddElement(order);
// derived entity type special order
EdmEntityType specialOrder = new EdmEntityType("NS", "SpecialOrder", order);
specialOrder.AddStructuralProperty("SpecialOrderProperty", EdmPrimitiveTypeKind.Guid);
model.AddElement(specialOrder);
// test entity
EdmEntityType testEntity = new EdmEntityType("System.Web.OData.Query.Expressions", "TestEntity");
testEntity.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Binary);
model.AddElement(testEntity);
// entity sets
EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance");
model.AddElement(container);
EdmEntitySet customers = container.AddEntitySet("Customers", customer);
EdmEntitySet orders = container.AddEntitySet("Orders", order);
// singletons
EdmSingleton vipCustomer = container.AddSingleton("VipCustomer", customer);
EdmSingleton mary = container.AddSingleton("Mary", customer);
// actions
EdmAction upgrade = new EdmAction("NS", "upgrade", returnType: null, isBound: true, entitySetPathExpression: null);
upgrade.AddParameter("entity", new EdmEntityTypeReference(customer, false));
model.AddElement(upgrade);
EdmAction specialUpgrade =
new EdmAction("NS", "specialUpgrade", returnType: null, isBound: true, entitySetPathExpression: null);
specialUpgrade.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
model.AddElement(specialUpgrade);
// functions
IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
IEdmTypeReference stringType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false);
IEdmTypeReference intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false);
EdmFunction IsUpgraded = new EdmFunction(
"NS",
"IsUpgraded",
returnType,
isBound: true,
entitySetPathExpression: null,
isComposable: false);
IsUpgraded.AddParameter("entity", new EdmEntityTypeReference(customer, false));
model.AddElement(IsUpgraded);
EdmFunction orderByCityAndAmount = new EdmFunction(
"NS",
"OrderByCityAndAmount",
stringType,
isBound: true,
entitySetPathExpression: null,
//.........这里部分代码省略.........
示例14: GetTargetEntitySetForSingleton
public void GetTargetEntitySetForSingleton()
{
var model = new EdmModel();
var container = new EdmEntityContainer("Fake", "Container");
model.AddElement(container);
var edmEntityType = new EdmEntityType("Fake", "EntityType");
var singleton = container.AddSingleton("Singleton", edmEntityType);
var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(edmEntityType, false), true, new EdmPathExpression("bindingparameter"), false);
function.AddParameter("bindingparameter", new EdmEntityTypeReference(edmEntityType, false));
var target = function.GetTargetEntitySet(singleton, model);
target.Should().BeNull();
}
示例15: InitializeEdmModel
private void InitializeEdmModel()
{
this.edmModel = new EdmModel();
EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer");
this.edmModel.AddElement(defaultContainer);
EdmComplexType addressType = new EdmComplexType("TestModel", "Address");
addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(/*isNullable*/false));
addressType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetString(/*isNullable*/false));
this.cityType = new EdmEntityType("TestModel", "City");
EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
cityType.AddKeys(cityIdProperty);
cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false));
cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
cityType.AddStructuralProperty("Restaurants", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(/*isNullable*/false)));
cityType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
this.edmModel.AddElement(cityType);
this.capitolCityType = new EdmEntityType("TestModel", "CapitolCity", cityType);
capitolCityType.AddStructuralProperty("CapitolType", EdmCoreModel.Instance.GetString( /*isNullable*/false));
this.edmModel.AddElement(capitolCityType);
EdmEntityType districtType = new EdmEntityType("TestModel", "District");
EdmStructuralProperty districtIdProperty = districtType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
districtType.AddKeys(districtIdProperty);
districtType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false));
districtType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
this.edmModel.AddElement(districtType);
cityType.AddBidirectionalNavigation(
new EdmNavigationPropertyInfo { Name = "Districts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many },
new EdmNavigationPropertyInfo { Name = "City", Target = cityType, TargetMultiplicity = EdmMultiplicity.One });
cityType.NavigationProperties().Single(np => np.Name == "Districts");
capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CapitolDistrict", Target = districtType, TargetMultiplicity = EdmMultiplicity.One });
capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OutlyingDistricts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many });
this.citySet = defaultContainer.AddEntitySet("Cities", cityType);
defaultContainer.AddEntitySet("Districts", districtType);
this.singletonCity = defaultContainer.AddSingleton("SingletonCity", cityType);
}