当前位置: 首页>>代码示例>>C#>>正文


C# EdmEntityType.Key方法代码示例

本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityType.Key方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityType.Key方法的具体用法?C# EdmEntityType.Key怎么用?C# EdmEntityType.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Edm.Library.EdmEntityType的用法示例。


在下文中一共展示了EdmEntityType.Key方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TaupoDefaultModelEdm

        public static IEdmModel TaupoDefaultModelEdm()
        {
            var model = new EdmModel();

            #region TaupoDefault Model code
            var phoneType = new EdmComplexType("NS1", "Phone");
            phoneType.AddStructuralProperty("PhoneNumber", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 16, isUnicode: false, isNullable: false));
            phoneType.AddStructuralProperty("Extension", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 16, isUnicode: false, isNullable: true));
            model.AddElement(phoneType);
            var phoneTypeReference = new EdmComplexTypeReference(phoneType, false);

            var contactDetailsType = new EdmComplexType("NS1", "ContactDetails");
            contactDetailsType.AddStructuralProperty("Email", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 32, isUnicode: false, isNullable: false));
            contactDetailsType.AddStructuralProperty("HomePhone", phoneTypeReference);
            contactDetailsType.AddStructuralProperty("WorkPhone", phoneTypeReference);
            contactDetailsType.AddStructuralProperty("MobilePhone", phoneTypeReference);
            model.AddElement(contactDetailsType);
            var contactDetailsTypeReference = new EdmComplexTypeReference(contactDetailsType, false);

            var concurrencyInfoType = new EdmComplexType("NS1", "ConcurrencyInfo");
            concurrencyInfoType.AddStructuralProperty("Token", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 20, isUnicode: false, isNullable: false), string.Empty, EdmConcurrencyMode.Fixed);
            concurrencyInfoType.AddStructuralProperty("QueriedDateTimeOffset", EdmCoreModel.Instance.GetDateTimeOffset(true));
            model.AddElement(concurrencyInfoType);
            var concurrencyInfoTypeReference = new EdmComplexTypeReference(concurrencyInfoType, false);

            var auditInfoType = new EdmComplexType("NS1", "AuditInfo");
            auditInfoType.AddStructuralProperty("ModifiedDate", EdmPrimitiveTypeKind.DateTimeOffset);
            auditInfoType.AddStructuralProperty("ModifiedBy", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 50, isUnicode: false, isNullable: false));
            auditInfoType.AddStructuralProperty("Concurrency", new EdmComplexTypeReference(concurrencyInfoType, false));
            model.AddElement(auditInfoType);
            var auditInfoTypeReference = new EdmComplexTypeReference(auditInfoType, false);

            var dimensionsType = new EdmComplexType("NS1", "Dimensions");
            dimensionsType.AddStructuralProperty("Width", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            dimensionsType.AddStructuralProperty("Height", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            dimensionsType.AddStructuralProperty("Depth", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            model.AddElement(dimensionsType);
            var dimensionsTypeReference = new EdmComplexTypeReference(dimensionsType, false);

            var suspiciousActivityType = new EdmEntityType("NS1", "SuspiciousActivity");
            suspiciousActivityType.AddKeys(suspiciousActivityType.AddStructuralProperty("SuspiciousActivityId", EdmPrimitiveTypeKind.Int32, false));
            suspiciousActivityType.AddStructuralProperty("Activity", EdmPrimitiveTypeKind.String);
            model.AddElement(suspiciousActivityType);

            var messageType = new EdmEntityType("NS1", "Message");
            var fromUsername = messageType.AddStructuralProperty("FromUsername", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            messageType.AddKeys(messageType.AddStructuralProperty("MessageId", EdmPrimitiveTypeKind.Int32, false), fromUsername);
            var toUsername = messageType.AddStructuralProperty("ToUsername", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            messageType.AddStructuralProperty("Sent", EdmPrimitiveTypeKind.DateTimeOffset);
            messageType.AddStructuralProperty("Subject", EdmPrimitiveTypeKind.String);
            messageType.AddStructuralProperty("Body", EdmCoreModel.Instance.GetString(true));
            messageType.AddStructuralProperty("IsRead", EdmCoreModel.Instance.GetBoolean(false));
            model.AddElement(messageType);

            var loginType = new EdmEntityType("NS1", "Login");
            loginType.AddKeys(loginType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)));
            var loginCustomerIdProperty = loginType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(loginType);

            var loginSentMessages = new EdmNavigationPropertyInfo { Name = "SentMessages", Target = messageType, TargetMultiplicity = EdmMultiplicity.Many };
            var messageSender = new EdmNavigationPropertyInfo { Name = "Sender", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { fromUsername }, PrincipalProperties = loginType.Key() };
            loginType.AddBidirectionalNavigation(loginSentMessages, messageSender);
            var loginReceivedMessages = new EdmNavigationPropertyInfo { Name = "ReceivedMessages", Target = messageType, TargetMultiplicity = EdmMultiplicity.Many };
            var messageRecipient = new EdmNavigationPropertyInfo { Name = "Recipient", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { fromUsername }, PrincipalProperties = loginType.Key() };
            loginType.AddBidirectionalNavigation(loginReceivedMessages, messageRecipient);
            var loginSuspiciousActivity = new EdmNavigationPropertyInfo { Name = "SuspiciousActivity", Target = suspiciousActivityType, TargetMultiplicity = EdmMultiplicity.Many };
            loginType.AddUnidirectionalNavigation(loginSuspiciousActivity);

            var lastLoginType = new EdmEntityType("NS1", "LastLogin");
            var userNameProperty = lastLoginType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            lastLoginType.AddKeys(userNameProperty);
            lastLoginType.AddStructuralProperty("LoggedIn", EdmPrimitiveTypeKind.DateTimeOffset);
            lastLoginType.AddStructuralProperty("LoggedOut", EdmCoreModel.Instance.GetDateTimeOffset(true));
            model.AddElement(lastLoginType);

            var loginLastLogin = new EdmNavigationPropertyInfo { Name = "LastLogin", Target = lastLoginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var lastLoginLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { userNameProperty }, PrincipalProperties = loginType.Key() };
            lastLoginType.AddBidirectionalNavigation(lastLoginLogin, loginLastLogin);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false));
            var orderCustomerId = orderType.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true));
            orderType.AddStructuralProperty("Concurrency", concurrencyInfoTypeReference);
            model.AddElement(orderType);

            var loginOrders = new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many };
            var orderLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            orderType.AddBidirectionalNavigation(orderLogin, loginOrders);

            var customerInfoType = new EdmEntityType("NS1", "CustomerInfo");
            customerInfoType.AddKeys(customerInfoType.AddStructuralProperty("CustomerInfoId", EdmPrimitiveTypeKind.Int32, false));
            customerInfoType.AddStructuralProperty("Information", EdmPrimitiveTypeKind.String);
            model.AddElement(customerInfoType);

            var customerType = new EdmEntityType("NS1", "Customer");
            var customerIdProperty = customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            customerType.AddKeys(customerIdProperty);
            customerType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isUnicode: false, isNullable: false));
            customerType.AddStructuralProperty("ContactInfo", contactDetailsTypeReference);
            model.AddElement(customerType);
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:ModelBuilder.cs

示例2: ModelWithAllConceptsEdm

        public static IEdmModel ModelWithAllConceptsEdm()
        {
            var stringType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String);

            var model = new EdmModel();
            var addressType = new EdmComplexType("NS1", "Address");
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("City", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/30, /*isUnicode*/true));
            model.AddElement(addressType);

            var zipCodeType = new EdmComplexType("NS1", "ZipCode");
            zipCodeType.AddStructuralProperty("Main", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
            zipCodeType.AddStructuralProperty("Extended", new EdmStringTypeReference(stringType, /*isNullable*/true, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
            model.AddElement(zipCodeType);
            addressType.AddStructuralProperty("Zip", new EdmComplexTypeReference(zipCodeType, false));

            var foreignAddressType = new EdmComplexType("NS1", "ForeignAddress", addressType, false);
            foreignAddressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
            model.AddElement(foreignAddressType);

            var personType = new EdmEntityType("NS1", "Person", null, true, false);
            personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
            model.AddElement(personType);

            var customerType = new EdmEntityType("NS1", "Customer", personType);
            customerType.AddStructuralProperty("IsVIP", EdmPrimitiveTypeKind.Boolean);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "LastUpdated", EdmCoreModel.Instance.GetDateTimeOffset(false), null, EdmConcurrencyMode.Fixed));
            customerType.AddStructuralProperty("BillingAddress", new EdmComplexTypeReference(addressType, false));
            customerType.AddStructuralProperty("ShippingAddress", new EdmComplexTypeReference(addressType, false));
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
            var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(orderType);

            var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            var container = new EdmEntityContainer("NS1", "MyContainer");
            container.AddEntitySet("PersonSet", personType);
            container.AddEntitySet("OrderSet", orderType);
            model.AddElement(container);

            var function = new EdmFunction("NS1", "Function1", EdmCoreModel.Instance.GetInt64(true));
            function.AddParameter("Param1", EdmCoreModel.Instance.GetInt32(true));
            container.AddFunctionImport(function);
            model.AddElement(function);

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:52,代码来源:ModelBuilder.cs

示例3: AssociationOnDeleteModelEdm

        public static IEdmModel AssociationOnDeleteModelEdm()
        {
            var model = new EdmModel();
            var customerType = new EdmEntityType("NS1", "Customer");
            customerType.AddKeys(customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(orderType);

            var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32);
            var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, OnDelete = EdmOnDeleteAction.Cascade };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key(), OnDelete = EdmOnDeleteAction.None };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:18,代码来源:ModelBuilder.cs

示例4: AssociationFkEdm

        public static IEdmModel AssociationFkEdm()
        {
            var model = new EdmModel();

            var customerType = new EdmEntityType("NS1", "Customer");
            customerType.AddKeys(customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            var orderTypeCustomerId = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32);
            model.AddElement(orderType);

            customerType.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "ToOrders",
                    Target = orderType,
                    TargetMultiplicity = EdmMultiplicity.Many,
                });

            orderType.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "Customer",
                    Target = customerType,
                    TargetMultiplicity = EdmMultiplicity.One,
                    DependentProperties = new[] { orderTypeCustomerId },
                    PrincipalProperties = orderType.Key()
                });

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:33,代码来源:ModelBuilder.cs

示例5: AssociationCompositeFkEdm

        public static IEdmModel AssociationCompositeFkEdm()
        {
            var model = new EdmModel();
            var customerType = new EdmEntityType("NS1", "Customer");
            customerType.AddKeys(customerType.AddStructuralProperty("Id1", EdmPrimitiveTypeKind.Int32));
            customerType.AddKeys(customerType.AddStructuralProperty("Id2", EdmPrimitiveTypeKind.Int32));
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id1", EdmPrimitiveTypeKind.Int32));
            var customerId1Property = orderType.AddStructuralProperty("CustomerId1", EdmPrimitiveTypeKind.Int32);
            var customerId2Property = orderType.AddStructuralProperty("CustomerId2", EdmPrimitiveTypeKind.Int32);
            model.AddElement(orderType);

            var navProp = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerId1Property, customerId2Property }, PrincipalProperties = customerType.Key() };
            orderType.AddUnidirectionalNavigation(navProp);

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:19,代码来源:ModelBuilder.cs

示例6: MultipleNamespacesEdm

        public static IEdmModel MultipleNamespacesEdm()
        {
            var model = new EdmModel();
            var personType = new EdmEntityType("NS1", "Person");
            personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(personType);

            var complexType1 = new EdmComplexType("NS3", "ComplexLevel1");
            model.AddElement(complexType1);
            var complexType2 = new EdmComplexType("NS2", "ComplexLevel2");
            model.AddElement(complexType2);
            var complexType3 = new EdmComplexType("NS2", "ComplexLevel3");
            model.AddElement(complexType3);

            complexType3.AddStructuralProperty("IntProperty", EdmPrimitiveTypeKind.Int32);
            complexType2.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType3, false));
            complexType1.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType2, false));
            personType.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType1, false));

            var customerType = new EdmEntityType("NS3", "Customer", personType);
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS2", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(orderType);

            var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32);
            var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:33,代码来源:ModelBuilder.cs

示例7: ConstructibleModelODataTestModelDefaultModel

        public void ConstructibleModelODataTestModelDefaultModel()
        {
            EdmModel model = new EdmModel();

            EdmComplexType aliases = new EdmComplexType("DefaultNamespace", "Aliases");
            EdmStructuralProperty aliasesAlternativeNames = aliases.AddStructuralProperty("AlternativeNames", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(false, 10, null, false)));
            model.AddElement(aliases);

            EdmComplexType phone = new EdmComplexType("DefaultNamespace", "Phone");
            EdmStructuralProperty phoneNumber = phone.AddStructuralProperty("PhoneNumber", EdmCoreModel.Instance.GetString(false, 16, null, false));
            EdmStructuralProperty phoneExtension = phone.AddStructuralProperty("Extension", EdmCoreModel.Instance.GetString(false, 16, null, true));
            model.AddElement(phone);

            EdmComplexType contact = new EdmComplexType("DefaultNamespace", "ContactDetails");
            EdmStructuralProperty contactEmailBag = contact.AddStructuralProperty("EmailBag", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(false, 32, null, false)));
            EdmStructuralProperty contactAlternativeNames = contact.AddStructuralProperty("AlternativeNames", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(false, 10, null, false)));
            EdmStructuralProperty contactAlias = contact.AddStructuralProperty("ContactAlias", new EdmComplexTypeReference(aliases, false));
            EdmStructuralProperty contactHomePhone = contact.AddStructuralProperty("HomePhone", new EdmComplexTypeReference(phone, false));
            EdmStructuralProperty contactWorkPhone = contact.AddStructuralProperty("WorkPhone", new EdmComplexTypeReference(phone, false));
            EdmStructuralProperty contactMobilePhoneBag = contact.AddStructuralProperty("MobilePhoneBag", EdmCoreModel.GetCollection(new EdmComplexTypeReference(phone, false)));
            model.AddElement(contact);

            EdmComplexType category = new EdmComplexType("DefaultNamespace", "ComplexToCategory");
            EdmStructuralProperty categoryTerm = category.AddStructuralProperty("Term", EdmCoreModel.Instance.GetString(false));
            EdmStructuralProperty categoryScheme = category.AddStructuralProperty("Scheme", EdmCoreModel.Instance.GetString(false));
            EdmStructuralProperty categoryLabel = category.AddStructuralProperty("Label", EdmCoreModel.Instance.GetString(false));
            model.AddElement(category);

            EdmComplexType dimensions = new EdmComplexType("DefaultNamespace", "Dimensions");
            EdmStructuralProperty dimensionsWidth = dimensions.AddStructuralProperty("Width", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            EdmStructuralProperty dimensionsHeight = dimensions.AddStructuralProperty("Height", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            EdmStructuralProperty dimensionsDepth = dimensions.AddStructuralProperty("Depth", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            model.AddElement(dimensions);

            EdmComplexType concurrency = new EdmComplexType("DefaultNamespace", "ConcurrencyInfo");
            EdmStructuralProperty concurrencyToken = concurrency.AddStructuralProperty("Token", EdmCoreModel.Instance.GetString(false, 20, null, false));
            EdmStructuralProperty concurrencyQueriedDateTime = concurrency.AddStructuralProperty("QueriedDateTime", EdmCoreModel.Instance.GetDateTimeOffset(true));
            model.AddElement(concurrency);

            EdmComplexType audit = new EdmComplexType("DefaultNamespace", "AuditInfo");
            EdmStructuralProperty auditModifiedDate = audit.AddStructuralProperty("ModifiedDate", EdmCoreModel.Instance.GetDateTimeOffset(false));
            EdmStructuralProperty auditModifiedBy = audit.AddStructuralProperty("ModifiedBy", EdmCoreModel.Instance.GetString(false, 50, null, false));
            EdmStructuralProperty auditConcurrency = audit.AddStructuralProperty("Concurrency", new EdmComplexTypeReference(concurrency, false));
            model.AddElement(audit);

            EdmEntityType customer = new EdmEntityType("DefaultNamespace", "Customer");
            EdmStructuralProperty customerId = customer.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(false));
            customer.AddKeys(customerId);
            EdmStructuralProperty customerName = customer.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false, 100, null, false));
            EdmStructuralProperty customerPrimaryContact = customer.AddStructuralProperty("PrimaryContactInfo", new EdmComplexTypeReference(contact, false));
            EdmStructuralProperty customerBackupContact = customer.AddStructuralProperty("BackupContactInfo", EdmCoreModel.GetCollection(new EdmComplexTypeReference(contact, false)));
            EdmStructuralProperty customerAuditing = customer.AddStructuralProperty("Auditing", new EdmComplexTypeReference(audit, false));
            EdmStructuralProperty customerThumbnail = customer.AddStructuralProperty("Thumbnail", EdmCoreModel.Instance.GetStream(false));
            EdmStructuralProperty customerVideo = customer.AddStructuralProperty("Video", EdmCoreModel.Instance.GetStream(false));
            model.AddElement(customer);

            EdmEntityType barcode = new EdmEntityType("DefaultNamespace", "Barcode");
            EdmStructuralProperty barcodeCode = barcode.AddStructuralProperty("Code", EdmCoreModel.Instance.GetInt32(false));
            barcode.AddKeys(barcodeCode);
            EdmStructuralProperty barcodeProductId = barcode.AddStructuralProperty("ProductId", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty barcodeText = barcode.AddStructuralProperty("Text", EdmCoreModel.Instance.GetString(false));
            model.AddElement(barcode);

            EdmEntityType incorrectScan = new EdmEntityType("DefaultNamespace", "IncorrectScan");
            EdmStructuralProperty incorrectScanId = incorrectScan.AddStructuralProperty("IncorrectScanId", EdmCoreModel.Instance.GetInt32(false));
            incorrectScan.AddKeys(incorrectScanId);
            EdmStructuralProperty incorrectScanExpectedCode = incorrectScan.AddStructuralProperty("ExpectedCode", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty incorrectScanActualCode = incorrectScan.AddStructuralProperty("ActualCode", EdmCoreModel.Instance.GetInt32(true));
            EdmStructuralProperty incorrectScanDate = incorrectScan.AddStructuralProperty("ScanDate", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDateTimeOffset(false)));
            EdmStructuralProperty incorrectScanDetails = incorrectScan.AddStructuralProperty("Details", EdmCoreModel.Instance.GetString(false));
            model.AddElement(incorrectScan);

            EdmEntityType barcodeDetail = new EdmEntityType("DefaultNamespace", "BarcodeDetail");
            EdmStructuralProperty barcodeDetailCode = barcodeDetail.AddStructuralProperty("Code", EdmCoreModel.Instance.GetInt32(false));
            barcodeDetail.AddKeys(barcodeDetailCode);
            EdmStructuralProperty barcodeDetailRegisteredTo = barcodeDetail.AddStructuralProperty("RegisteredTo", EdmCoreModel.Instance.GetString(false));
            model.AddElement(barcodeDetail);

            EdmEntityType complaint = new EdmEntityType("DefaultNamespace", "Complaint");
            EdmStructuralProperty complaintId = complaint.AddStructuralProperty("ComplaintId", EdmCoreModel.Instance.GetInt32(false));
            complaint.AddKeys(complaintId);
            EdmStructuralProperty complaintCustomerId = complaint.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true));
            EdmStructuralProperty complaintLogged = complaint.AddStructuralProperty("Logged", EdmCoreModel.Instance.GetDateTimeOffset(false));
            EdmStructuralProperty complaintDetails = complaint.AddStructuralProperty("Details", EdmCoreModel.Instance.GetString(false));
            model.AddElement(complaint);

            EdmEntityType resolution = new EdmEntityType("DefaultNamespace", "Resolution");
            EdmStructuralProperty resolutionId = resolution.AddStructuralProperty("ResolutionId", EdmCoreModel.Instance.GetInt32(false));
            resolution.AddKeys(resolutionId);
            EdmStructuralProperty resolutionDetails = resolution.AddStructuralProperty("Details", EdmCoreModel.Instance.GetString(false));
            model.AddElement(resolution);

            EdmEntityType login = new EdmEntityType("DefaultNamespace", "Login");
            EdmStructuralProperty loginUsername = login.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(false, 50, null, false));
            login.AddKeys(loginUsername);
            EdmStructuralProperty loginCustomerId = login.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(login);

            EdmEntityType suspiciousActivity = new EdmEntityType("DefaultNamespace", "SuspiciousActivity");
            EdmStructuralProperty suspiciousActivityId = suspiciousActivity.AddStructuralProperty("SuspiciousActivityId", EdmCoreModel.Instance.GetInt32(false));
//.........这里部分代码省略.........
开发者ID:AlineGuan,项目名称:odata.net,代码行数:101,代码来源:ConstructibleModelTestsUsingConverter.cs

示例8: DollarMetadata_Works_WithMultipleReferentialConstraints_ForUntypeModel

        public void DollarMetadata_Works_WithMultipleReferentialConstraints_ForUntypeModel()
        {
            // Arrange
            EdmModel model = new EdmModel();

            EdmEntityType customer = new EdmEntityType("DefaultNamespace", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            customer.AddStructuralProperty("Name",
                EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isUnicode: null, isNullable: false));
            model.AddElement(customer);

            EdmEntityType order = new EdmEntityType("DefaultNamespace", "Order");
            order.AddKeys(order.AddStructuralProperty("OrderId", EdmCoreModel.Instance.GetInt32(false)));
            EdmStructuralProperty orderCustomerId = order.AddStructuralProperty("CustomerForeignKey", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(order);

            customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many
                },
                new EdmNavigationPropertyInfo
                {
                    Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                    DependentProperties = new[] { orderCustomerId },
                    PrincipalProperties = customer.Key()
                });

            const string expect =
                "        <Property Name=\"CustomerForeignKey\" Type=\"Edm.Int32\" />\r\n" +
                "        <NavigationProperty Name=\"Customer\" Type=\"DefaultNamespace.Customer\" Partner=\"Orders\">\r\n" +
                "          <ReferentialConstraint Property=\"CustomerForeignKey\" ReferencedProperty=\"CustomerId\" />\r\n" +
                "        </NavigationProperty>";

            HttpConfiguration config = new[] { typeof(MetadataController) }.GetHttpConfiguration();
            HttpServer server = new HttpServer(config);
            config.MapODataServiceRoute("odata", "odata", model);

            HttpClient client = new HttpClient(server);

            // Act
            HttpResponseMessage response = client.GetAsync("http://localhost/odata/$metadata").Result;

            // Assert
            Assert.True(response.IsSuccessStatusCode);
            Assert.Equal("application/xml", response.Content.Headers.ContentType.MediaType);
            Assert.Contains(expect, response.Content.ReadAsStringAsync().Result);
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:48,代码来源:MetadataControllerTest.cs

示例9: ModelWithReferentialConstraintWhoseDependentPropertiesNotPartOfDependentEntity

        public static IEdmModel ModelWithReferentialConstraintWhoseDependentPropertiesNotPartOfDependentEntity()
        {
            EdmModel model = new EdmModel();

            var entity1 = new EdmEntityType("Foo", "Bar");
            var id1 = new EdmStructuralProperty(entity1, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity1.AddKeys(id1);

            var entity2 = new EdmEntityType("Foo", "Baz");
            var id2 = new EdmStructuralProperty(entity2, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity2.AddKeys(id2);

            StubEdmNavigationProperty navProp1 = new StubEdmNavigationProperty("ToBaz");
            StubEdmNavigationProperty navProp2 = new StubEdmNavigationProperty("ToBar");
            navProp1.Type = new EdmEntityTypeReference(entity2, false);
            navProp1.DeclaringType = entity1;
            navProp1.ReferentialConstraint = EdmReferentialConstraint.Create(new[] { new EdmStructuralProperty(entity2, "Id1", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None) }, entity2.Key());
            navProp1.Partner = navProp2;

            navProp2.Type = new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entity1, false)));
            navProp2.DeclaringType = entity2;
            navProp2.Partner = navProp1;

            entity1.AddProperty(navProp1);
            entity2.AddProperty(navProp2);

            model.AddElement(entity1);
            model.AddElement(entity2);

            return model;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:31,代码来源:ValidationTestModelBuilder.cs

示例10: ModelWithInvalidDependentProperties

        public static IEdmModel ModelWithInvalidDependentProperties()
        {
            EdmModel model = new EdmModel();

            var entity1 = new EdmEntityType("Foo", "Bar");
            var id1 = new EdmStructuralProperty(entity1, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity1.AddKeys(id1);

            var entity2 = new EdmEntityType("Foo", "Baz");
            var id2 = new EdmStructuralProperty(entity2, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity2.AddKeys(id2);

            EdmNavigationProperty entity1Navigation = entity1.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "ToBaz", Target = entity2, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { id2 }, PrincipalProperties = entity2.Key() },
                new EdmNavigationPropertyInfo() { Name = "ToBar", TargetMultiplicity = EdmMultiplicity.Many }); 

            model.AddElement(entity1);

            return model;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:20,代码来源:ValidationTestModelBuilder.cs


注:本文中的Microsoft.OData.Edm.Library.EdmEntityType.Key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。