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

            // Create and add product entity type.
            EdmEntityType product = new EdmEntityType("NS", "Product");
            product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            product.AddStructuralProperty("Price", EdmPrimitiveTypeKind.Double);
            model.AddElement(product);

            // Create and add category entity type.
            EdmEntityType category = new EdmEntityType("NS", "Category");
            category.AddKeys(category.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            category.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(category);

            // Set navigation from product to category.
            EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo();
            propertyInfo.Name = "Category";
            propertyInfo.TargetMultiplicity = EdmMultiplicity.One;
            propertyInfo.Target = category;
            EdmNavigationProperty productCategory = product.AddUnidirectionalNavigation(propertyInfo);

            // Create and add entity container.
            EdmEntityContainer container = new EdmEntityContainer("NS", "DefaultContainer");
            model.AddElement(container);

            // Create and add entity set for product and category.
            EdmEntitySet products = container.AddEntitySet("Products", product);
            EdmEntitySet categories = container.AddEntitySet("Categories", category);
            products.AddNavigationTarget(productCategory, categories);

            return model;
        }
Exemple #2
0
        /// <summary>
        /// Creates two navigation properties representing an association between two entity types.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <param name="partnerInfo">Information to create the partner navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");
            EdmUtil.CheckArgumentNull(partnerInfo, "partnerInfo");
            EdmUtil.CheckArgumentNull(partnerInfo.Name, "partnerInfo.Name");
            EdmUtil.CheckArgumentNull(partnerInfo.Target, "partnerInfo.Target");

            EdmNavigationProperty end1 = new EdmNavigationProperty(
                partnerInfo.Target,
                propertyInfo.Name,
                CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"),
                propertyInfo.DependentProperties,
                propertyInfo.PrincipalProperties,
                propertyInfo.ContainsTarget,
                propertyInfo.OnDelete);

            EdmNavigationProperty end2 = new EdmNavigationProperty(
                propertyInfo.Target,
                partnerInfo.Name,
                CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"),
                partnerInfo.DependentProperties,
                partnerInfo.PrincipalProperties,
                partnerInfo.ContainsTarget,
                partnerInfo.OnDelete);

            end1.partner = end2;
            end2.partner = end1;
            return(end1);
        }
        public void TestCloneEdmnavigationPropertyInfo()
        {
            var type = new EdmEntityType("NS", "name");
            var property1 = new EdmStructuralProperty(type, "property1", EdmCoreModel.Instance.GetInt32(false));
            var property2 = new EdmStructuralProperty(type, "property2", EdmCoreModel.Instance.GetInt32(false));
            EdmNavigationPropertyInfo navigationPropertyInfo = new EdmNavigationPropertyInfo
            {
                ContainsTarget = true,
                DependentProperties = new[] {property1}, 
                Name = "navPropInfo", 
                OnDelete = EdmOnDeleteAction.Cascade, 
                PrincipalProperties = new[] {property2}, 
                Target = type, 
                TargetMultiplicity = EdmMultiplicity.Many
            };
            var cloneNavigationPropertyInfo = navigationPropertyInfo.Clone();

            Assert.AreEqual(navigationPropertyInfo.ContainsTarget, cloneNavigationPropertyInfo.ContainsTarget);
            Assert.AreEqual(navigationPropertyInfo.Name, cloneNavigationPropertyInfo.Name);
            Assert.AreEqual(navigationPropertyInfo.DependentProperties, cloneNavigationPropertyInfo.DependentProperties);
            Assert.AreEqual(navigationPropertyInfo.OnDelete, cloneNavigationPropertyInfo.OnDelete);
            Assert.AreEqual(navigationPropertyInfo.Target, cloneNavigationPropertyInfo.Target);
            Assert.AreEqual(navigationPropertyInfo.PrincipalProperties, cloneNavigationPropertyInfo.PrincipalProperties);
            Assert.AreEqual(navigationPropertyInfo.TargetMultiplicity, cloneNavigationPropertyInfo.TargetMultiplicity);
        }
        public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, IEnumerable<string> propertyNames)
        {
            _source = source;
            _entityType = new EdmEntityType(entityType.Namespace, entityType.Name);

            foreach (var property in entityType.StructuralProperties())
            {
                if (propertyNames.Contains(property.Name))
                    _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString, property.ConcurrencyMode);
            }

            foreach (var property in entityType.NavigationProperties())
            {
                if (propertyNames.Contains(property.Name))
                {
                    var navInfo = new EdmNavigationPropertyInfo()
                    {
                        ContainsTarget = property.ContainsTarget,
                        DependentProperties = property.DependentProperties(),
                        PrincipalProperties = property.PrincipalProperties(),
                        Name = property.Name,
                        OnDelete = property.OnDelete,
                        Target = property.Partner != null 
                            ? property.Partner.DeclaringEntityType()
                            : property.Type.TypeKind() == EdmTypeKind.Collection
                            ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType
                            : property.Type.TypeKind() == EdmTypeKind.Entity
                            ? property.Type.Definition as IEdmEntityType
                            : null,
                        TargetMultiplicity = property.TargetMultiplicity(),
                    };
                    _entityType.AddUnidirectionalNavigation(navInfo);
                }
            }
        }
Exemple #5
0
        private static void ReferentialConstraintDemo()
        {
            Console.WriteLine("ReferentialConstraintDemo");

            EdmModel model = new EdmModel();
            var customer = new EdmEntityType("ns", "Customer");
            model.AddElement(customer);
            var customerId = customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false);
            customer.AddKeys(customerId);
            var address = new EdmComplexType("ns", "Address");
            model.AddElement(address);
            var code = address.AddStructuralProperty("gid", EdmPrimitiveTypeKind.Guid);
            customer.AddStructuralProperty("addr", new EdmComplexTypeReference(address, true));

            var order = new EdmEntityType("ns", "Order");
            model.AddElement(order);
            var oId = order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false);
            order.AddKeys(oId);

            var orderCustomerId = order.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);

            var nav = new EdmNavigationPropertyInfo()
            {
                Name = "NavCustomer",
                Target = customer,
                TargetMultiplicity = EdmMultiplicity.One,
                DependentProperties = new[] { orderCustomerId },
                PrincipalProperties = new[] { customerId }
            };
            order.AddUnidirectionalNavigation(nav);

            ShowModel(model);
        }
Exemple #6
0
        /// <summary>
        /// Creates and adds a unidirectional navigation property to this type.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public EdmNavigationProperty AddUnidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");

            EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationProperty(this, propertyInfo);

            this.AddProperty(property);
            return(property);
        }
Exemple #7
0
        /// <summary>
        /// Creates and adds a navigation property to this type and adds its navigation partner to the navigation target type.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <param name="partnerInfo">Information to create the partner navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public EdmNavigationProperty AddBidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");

            EdmEntityType targetType = propertyInfo.Target as EdmEntityType;

            if (targetType == null)
            {
                throw new ArgumentException("propertyInfo.Target", Strings.Constructable_TargetMustBeStock(typeof(EdmEntityType).FullName));
            }

            EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo));

            this.AddProperty(property);
            targetType.AddProperty(property.Partner);
            return(property);
        }
Exemple #8
0
        /// <summary>
        /// The puspose of this method is to make sure that some of the <paramref name="partnerInfo"/> fields are set to valid partner defaults.
        /// For example if <paramref name="partnerInfo"/>.Target is null, it will be set to this entity type. If <paramref name="partnerInfo"/>.TargetMultiplicity
        /// is unknown, it will be set to 0..1, etc.
        /// Whenever this method applies new values to <paramref name="partnerInfo"/>, it will return a copy of it (thus won't modify the original).
        /// If <paramref name="partnerInfo"/> is null, a new info object will be produced.
        /// </summary>
        /// <param name="propertyInfo">Primary navigation property info.</param>
        /// <param name="partnerInfo">Partner navigation property info. May be null.</param>
        /// <returns>Partner info.</returns>
        private EdmNavigationPropertyInfo FixUpDefaultPartnerInfo(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmNavigationPropertyInfo partnerInfoOverride = null;

            if (partnerInfo == null)
            {
                partnerInfo = partnerInfoOverride = new EdmNavigationPropertyInfo();
            }

            if (partnerInfo.Name == null)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.Name = (propertyInfo.Name ?? String.Empty) + "Partner";
            }

            if (partnerInfo.Target == null)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.Target = this;
            }

            if (partnerInfo.TargetMultiplicity == EdmMultiplicity.Unknown)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.TargetMultiplicity = EdmMultiplicity.ZeroOrOne;
            }

            return(partnerInfoOverride ?? partnerInfo);
        }
Exemple #9
0
        private static void AddNavigationProperties(
            IModel efModel, INavigation navi,
            EdmModel model, IDictionary<IAnnotatable, IEdmElement> elementMap)
        {
            if (!navi.PointsToPrincipal())
            {
                return;
            }
            var naviPair = new INavigation[] { navi, navi.FindInverse() };
            var navPropertyInfos = new EdmNavigationPropertyInfo[2];
            for (var i = 0; i < 2; i++)
            {
                var efEnd = naviPair[i];
                if (efEnd == null) continue;

                var efEntityType = efEnd.DeclaringEntityType;
                if (!elementMap.ContainsKey(efEntityType))
                {
                    continue;
                }
                var entityType = elementMap[efEntityType] as IEdmEntityType;
                var efTargetEntityType = naviPair[i].GetTargetType();
                if (!elementMap.ContainsKey(efTargetEntityType))
                {
                    continue;
                }
                var targetEntityType = elementMap[
                    efTargetEntityType] as IEdmEntityType;
                navPropertyInfos[i] = new EdmNavigationPropertyInfo()
                {
                    ContainsTarget = false,
                    Name = naviPair[i].Name,
                    // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
                    //OnDelete = efEnd.DeleteBehavior == OperationAction.Cascade
                    //    ? EdmOnDeleteAction.Cascade : EdmOnDeleteAction.None,
                    OnDelete = EdmOnDeleteAction.None,
                    Target = targetEntityType,
                    TargetMultiplicity = ModelProducer.GetEdmMultiplicity(
                        naviPair[i]),
                };
                var foreignKey = naviPair[i].ForeignKey;
                if (foreignKey != null && naviPair[i].PointsToPrincipal())
                {
                    navPropertyInfos[i].DependentProperties = foreignKey.Properties
                        .Select(p => entityType.FindProperty(p.Name) as IEdmStructuralProperty);
                    navPropertyInfos[i].PrincipalProperties = foreignKey.PrincipalKey.Properties
                        .Select(p => targetEntityType.FindProperty(p.Name) as IEdmStructuralProperty);
                }
            }
            if (navPropertyInfos[0] == null && navPropertyInfos[1] != null)
            {
                var efEntityType = navi.GetTargetType();
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[1].Name) == null)
                {
                    entityType.AddUnidirectionalNavigation(navPropertyInfos[1]);
                }
            }
            if (navPropertyInfos[0] != null && navPropertyInfos[1] == null)
            {
                var efEntityType = navi.DeclaringEntityType;
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
                {
                    entityType.AddUnidirectionalNavigation(navPropertyInfos[0]);
                }
            }
            if (navPropertyInfos[0] != null && navPropertyInfos[1] != null)
            {
                var efEntityType = navi.DeclaringEntityType;
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
                {
                    entityType.AddBidirectionalNavigation(
                        navPropertyInfos[0], navPropertyInfos[1]);
                }
            }
        }
Exemple #10
0
        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);

            var customerOrders = new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
            var orderCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { orderCustomerId }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(customerOrders, orderCustomer);
            var customerLogins = new EdmNavigationPropertyInfo { Name = "Logins", Target = loginType, TargetMultiplicity = EdmMultiplicity.Many, };
            var loginCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { loginCustomerIdProperty }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(customerLogins, loginCustomer);
            var customerHusband = new EdmNavigationPropertyInfo { Name = "Husband", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var customerWife = new EdmNavigationPropertyInfo { Name = "Wife", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            customerType.AddBidirectionalNavigation(customerHusband, customerWife);
            var customerInfo = new EdmNavigationPropertyInfo { Name = "CustomerInfo", Target = customerInfoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            customerType.AddUnidirectionalNavigation(customerInfo);

            var productType = new EdmEntityType("NS1", "Product");
            productType.AddKeys(productType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false));
            productType.AddStructuralProperty("Description", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: true, maxLength: 1000, isUnicode: false));
            productType.AddStructuralProperty("Dimensions", dimensionsTypeReference);
            productType.AddStructuralProperty("BaseConcurrency", EdmCoreModel.Instance.GetString(false), string.Empty, EdmConcurrencyMode.Fixed);
            productType.AddStructuralProperty("ComplexConcurrency", concurrencyInfoTypeReference);
            productType.AddStructuralProperty("NestedComplexConcurrency", auditInfoTypeReference);
            model.AddElement(productType);

            var barCodeType = new EdmEntityType("NS1", "Barcode");
            barCodeType.AddKeys(barCodeType.AddStructuralProperty("Code", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50)));
            var barCodeProductIdProperty = barCodeType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            barCodeType.AddStructuralProperty("Text", EdmPrimitiveTypeKind.String);
            model.AddElement(barCodeType);

            var productBarCodes = new EdmNavigationPropertyInfo { Name = "Barcodes", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.Many };
            var barCodeProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { barCodeProductIdProperty }, PrincipalProperties = productType.Key() };
            barCodeType.AddBidirectionalNavigation(barCodeProduct, productBarCodes);

            var incorrectScanType = new EdmEntityType("NS1", "IncorrectScan");
            incorrectScanType.AddKeys(incorrectScanType.AddStructuralProperty("IncorrectScanId", EdmPrimitiveTypeKind.Int32, false));
            var expectedCodeProperty = incorrectScanType.AddStructuralProperty("ExpectedCode", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50));
            var actualCodeProperty = incorrectScanType.AddStructuralProperty("ActualCode", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: true, maxLength: 50));
            incorrectScanType.AddStructuralProperty("ScanDate", EdmPrimitiveTypeKind.DateTimeOffset);
            incorrectScanType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(incorrectScanType);

            var barCodeIncorrectScan = new EdmNavigationPropertyInfo { Name = "BadScans", Target = incorrectScanType, TargetMultiplicity = EdmMultiplicity.Many };
            var incorrectScanExpectedBarCode = new EdmNavigationPropertyInfo { Name = "ExpectedBarcode", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { expectedCodeProperty }, PrincipalProperties = barCodeType.Key() };
            incorrectScanType.AddBidirectionalNavigation(incorrectScanExpectedBarCode, barCodeIncorrectScan);
            var actualBarcode = new EdmNavigationPropertyInfo { Name = "ActualBarcode", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { actualCodeProperty }, PrincipalProperties = barCodeType.Key() };
            incorrectScanType.AddUnidirectionalNavigation(actualBarcode);

            var barCodeDetailType = new EdmEntityType("NS1", "BarcodeDetail");
            var codeProperty = barCodeDetailType.AddStructuralProperty("Code", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50));
            barCodeDetailType.AddKeys(codeProperty);
            barCodeDetailType.AddStructuralProperty("RegisteredTo", EdmPrimitiveTypeKind.String);
            model.AddElement(barCodeDetailType);

            var barCodeDetail = new EdmNavigationPropertyInfo { Name = "Detail", Target = barCodeDetailType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = barCodeType.Key(), PrincipalProperties = barCodeDetailType.Key() };
            barCodeType.AddUnidirectionalNavigation(barCodeDetail);

            var resolutionType = new EdmEntityType("NS1", "Resolution");
            resolutionType.AddKeys(resolutionType.AddStructuralProperty("ResolutionId", EdmPrimitiveTypeKind.Int32, false));
            resolutionType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(resolutionType);

            var complaintType = new EdmEntityType("NS1", "Complaint");
            complaintType.AddKeys(complaintType.AddStructuralProperty("ComplaintId", EdmPrimitiveTypeKind.Int32, false));
            var complaintCustomerId = complaintType.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true));
            complaintType.AddStructuralProperty("Logged", EdmPrimitiveTypeKind.DateTimeOffset);
            complaintType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(complaintType);

            var complaintCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { complaintCustomerId }, PrincipalProperties = customerType.Key() };
            complaintType.AddUnidirectionalNavigation(complaintCustomer);
            var complaintResolution = new EdmNavigationPropertyInfo { Name = "Resolution", Target = resolutionType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var resolutionComplaint = new EdmNavigationPropertyInfo { Name = "Complaint", Target = complaintType, TargetMultiplicity = EdmMultiplicity.One };
            complaintType.AddBidirectionalNavigation(complaintResolution, resolutionComplaint);

            var smartCardType = new EdmEntityType("NS1", "SmartCard");
            var smartCardUsername = smartCardType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            smartCardType.AddKeys(smartCardUsername);
            smartCardType.AddStructuralProperty("CardSerial", EdmPrimitiveTypeKind.String);
            smartCardType.AddStructuralProperty("Issued", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(smartCardType);

            var smartCardLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { smartCardUsername }, PrincipalProperties = loginType.Key() };
            smartCardType.AddUnidirectionalNavigation(smartCardLogin);
            var smartCardLastLogin = new EdmNavigationPropertyInfo { Name = "LastLogin", Target = lastLoginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            smartCardType.AddUnidirectionalNavigation(smartCardLastLogin);

            var rsaTokenType = new EdmEntityType("NS1", "RSAToken");
            rsaTokenType.AddKeys(rsaTokenType.AddStructuralProperty("Serial", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 20, isUnicode: false)));
            rsaTokenType.AddStructuralProperty("Issued", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(rsaTokenType);

            var rsaTokenLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One };
            rsaTokenType.AddUnidirectionalNavigation(rsaTokenLogin);

            var passwordResetType = new EdmEntityType("NS1", "PasswordReset");
            passwordResetType.AddKeys(passwordResetType.AddStructuralProperty("ResetNo", EdmPrimitiveTypeKind.Int32, false));
            var passwordResetUsername = passwordResetType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            passwordResetType.AddStructuralProperty("TempPassword", EdmPrimitiveTypeKind.String);
            passwordResetType.AddStructuralProperty("EmailedTo", EdmPrimitiveTypeKind.String);
            model.AddElement(passwordResetType);

            var passwordResetLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { passwordResetUsername }, PrincipalProperties = loginType.Key() };
            passwordResetType.AddUnidirectionalNavigation(passwordResetLogin);

            var pageViewType = new EdmEntityType("NS1", "PageView");
            pageViewType.AddKeys(pageViewType.AddStructuralProperty("PageViewId", EdmPrimitiveTypeKind.Int32, false));
            var pageViewUsername = pageViewType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            pageViewType.AddStructuralProperty("Viewed", EdmPrimitiveTypeKind.DateTimeOffset);
            pageViewType.AddStructuralProperty("PageUrl", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 500, isUnicode: false));
            model.AddElement(pageViewType);

            var pageViewLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { pageViewUsername }, PrincipalProperties = loginType.Key() };
            pageViewType.AddUnidirectionalNavigation(pageViewLogin);

            var productPageViewType = new EdmEntityType("NS1", "ProductPageView", pageViewType);
            var productPageViewProductId = productPageViewType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(productPageViewType);

            var productPageViewProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productPageViewProductId }, PrincipalProperties = productType.Key() };
            productPageViewType.AddUnidirectionalNavigation(productPageViewProduct);

            var supplierType = new EdmEntityType("NS1", "Supplier");
            supplierType.AddKeys(supplierType.AddStructuralProperty("SupplierId", EdmPrimitiveTypeKind.Int32, false));
            supplierType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(supplierType);

            var supplierProducts = new EdmNavigationPropertyInfo { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many };
            var productSuppliers = new EdmNavigationPropertyInfo { Name = "Suppliers", Target = supplierType, TargetMultiplicity = EdmMultiplicity.Many };
            supplierType.AddBidirectionalNavigation(supplierProducts, productSuppliers);

            var supplierLogoType = new EdmEntityType("NS1", "SupplierLogo");
            var supplierLogoSupplierId = supplierLogoType.AddStructuralProperty("SupplierId", EdmPrimitiveTypeKind.Int32, false);
            supplierLogoType.AddKeys(supplierLogoSupplierId);
            supplierLogoType.AddStructuralProperty("Logo", EdmCoreModel.Instance.GetBinary(isNullable: false, isUnbounded: false, maxLength: 500));
            model.AddElement(supplierLogoType);

            var supplierSupplierLogo = new EdmNavigationPropertyInfo { Name = "Logo", Target = supplierLogoType, TargetMultiplicity = EdmMultiplicity.One, PrincipalProperties = new[] { supplierLogoSupplierId }, DependentProperties = supplierType.Key() };
            supplierType.AddUnidirectionalNavigation(supplierSupplierLogo);

            var supplierInfoType = new EdmEntityType("NS1", "SupplierInfo");
            supplierInfoType.AddKeys(supplierInfoType.AddStructuralProperty("SupplierInfoId", EdmPrimitiveTypeKind.Int32, false));
            supplierInfoType.AddStructuralProperty("Information", EdmPrimitiveTypeKind.String);
            model.AddElement(supplierInfoType);

            var supplierInfoSupplier = new EdmNavigationPropertyInfo { Name = "Supplier", Target = supplierType, TargetMultiplicity = EdmMultiplicity.One, OnDelete = EdmOnDeleteAction.Cascade };
            supplierInfoType.AddUnidirectionalNavigation(supplierInfoSupplier);

            var orderNoteType = new EdmEntityType("NS1", "OrderNote");
            orderNoteType.AddKeys(orderNoteType.AddStructuralProperty("NoteId", EdmPrimitiveTypeKind.Int32, false));
            orderNoteType.AddStructuralProperty("Note", EdmPrimitiveTypeKind.String);
            model.AddElement(orderNoteType);

            var orderNoteOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One };
            var orderOrderNotes = new EdmNavigationPropertyInfo { Name = "Notes", Target = orderNoteType, TargetMultiplicity = EdmMultiplicity.Many, OnDelete = EdmOnDeleteAction.Cascade };
            orderNoteType.AddBidirectionalNavigation(orderNoteOrder, orderOrderNotes);

            var orderQualityCheckType = new EdmEntityType("NS1", "OrderQualityCheck");
            var orderQualityCheckOrderId = orderQualityCheckType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false);
            orderQualityCheckType.AddKeys(orderQualityCheckOrderId);
            orderQualityCheckType.AddStructuralProperty("CheckedBy", EdmPrimitiveTypeKind.String);
            orderQualityCheckType.AddStructuralProperty("CheckedDateTime", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(orderQualityCheckType);

            var orderQualityCheckOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderQualityCheckOrderId }, PrincipalProperties = orderType.Key() };
            orderQualityCheckType.AddUnidirectionalNavigation(orderQualityCheckOrder);

            var orderLineType = new EdmEntityType("NS1", "OrderLine");
            var orderLineOrderId = orderLineType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false);
            var orderLineProductId = orderLineType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            orderLineType.AddKeys(orderLineOrderId, orderLineProductId);
            orderLineType.AddStructuralProperty("Quantity", EdmPrimitiveTypeKind.Int32);
            orderLineType.AddStructuralProperty("ConcurrencyToken", EdmCoreModel.Instance.GetString(false), string.Empty, EdmConcurrencyMode.Fixed);
            model.AddElement(orderLineType);

            var orderLineOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderLineOrderId }, PrincipalProperties = orderType.Key() };
            var orderOrderLine = new EdmNavigationPropertyInfo { Name = "OrderLines", Target = orderLineType, TargetMultiplicity = EdmMultiplicity.Many };
            orderLineType.AddBidirectionalNavigation(orderLineOrder, orderOrderLine);

            var orderLineProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderLineProductId }, PrincipalProperties = productType.Key() };
            orderLineType.AddUnidirectionalNavigation(orderLineProduct);

            var backOrderLineType = new EdmEntityType("NS1", "BackOrderLine", orderLineType);
            backOrderLineType.AddStructuralProperty("ETA", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(backOrderLineType);

            var backOrderLineSupplier = new EdmNavigationPropertyInfo { Name = "Supplier", Target = supplierType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var supplierBackOrderLines = new EdmNavigationPropertyInfo { Name = "BackOrderLines", Target = backOrderLineType, TargetMultiplicity = EdmMultiplicity.Many };
            backOrderLineType.AddBidirectionalNavigation(backOrderLineSupplier, supplierBackOrderLines);

            var backOrderLine2Type = new EdmEntityType("NS1", "BackOrderLine2", backOrderLineType);
            model.AddElement(backOrderLine2Type);

            var discontinuedProductType = new EdmEntityType("NS1", "DiscontinuedProduct", productType);
            discontinuedProductType.AddStructuralProperty("Discontinued", EdmPrimitiveTypeKind.DateTimeOffset);
            var replacementProductId = discontinuedProductType.AddStructuralProperty("ReplacementProductId", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(discontinuedProductType);

            var discontinuedProductReplacement = new EdmNavigationPropertyInfo { Name = "ReplacedBy", Target = productType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { replacementProductId }, PrincipalProperties = productType.Key() };
            var productReplaces = new EdmNavigationPropertyInfo { Name = "Replaces", Target = discontinuedProductType, TargetMultiplicity = EdmMultiplicity.Many, };
            discontinuedProductType.AddBidirectionalNavigation(discontinuedProductReplacement, productReplaces);

            var productDetailType = new EdmEntityType("NS1", "ProductDetail");
            var productDetailProductId = productDetailType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            productDetailType.AddKeys(productDetailProductId);
            productDetailType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(productDetailType);

            var productDetailProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productDetailProductId }, PrincipalProperties = productType.Key() };
            var productProductDetail = new EdmNavigationPropertyInfo { Name = "Detail", Target = productDetailType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            productDetailType.AddBidirectionalNavigation(productDetailProduct, productProductDetail);

            var productReviewType = new EdmEntityType("NS1", "ProductReview");
            var productReviewProductId = productReviewType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            productReviewType.AddKeys(productReviewProductId, productReviewType.AddStructuralProperty("ReviewId", EdmPrimitiveTypeKind.Int32, false));
            productReviewType.AddStructuralProperty("Review", EdmPrimitiveTypeKind.String);
            model.AddElement(productReviewType);

            var productReviewProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productReviewProductId }, PrincipalProperties = productType.Key() };
            var productProductReviews = new EdmNavigationPropertyInfo { Name = "Reviews", Target = productReviewType, TargetMultiplicity = EdmMultiplicity.Many };
            productReviewType.AddBidirectionalNavigation(productReviewProduct, productProductReviews);

            var productPhotoType = new EdmEntityType("NS1", "ProductPhoto");
            var productPhotoProductId = productPhotoType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            productPhotoType.AddKeys(productPhotoProductId, productPhotoType.AddStructuralProperty("PhotoId", EdmPrimitiveTypeKind.Int32, false));
            productPhotoType.AddStructuralProperty("Photo", EdmPrimitiveTypeKind.Binary);
            model.AddElement(productPhotoType);

            var productProductPhotos = new EdmNavigationPropertyInfo { Name = "Photos", Target = productPhotoType, TargetMultiplicity = EdmMultiplicity.Many };
            var productPhotoProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productPhotoProductId }, PrincipalProperties = productType.Key() };
            productType.AddBidirectionalNavigation(productProductPhotos, productPhotoProduct);

            var productWebFeatureType = new EdmEntityType("NS1", "ProductWebFeature");
            productWebFeatureType.AddKeys(productWebFeatureType.AddStructuralProperty("FeatureId", EdmPrimitiveTypeKind.Int32, false));
            var productWebFeatureProductId = productWebFeatureType.AddStructuralProperty("ProductId", EdmCoreModel.Instance.GetInt32(true));
            var productWebFeaturePhotoId = productWebFeatureType.AddStructuralProperty("PhotoId", EdmCoreModel.Instance.GetInt32(true));
            var productWebFeatureReviewId = productWebFeatureType.AddStructuralProperty("ReviewId", EdmCoreModel.Instance.GetInt32(true));
            productWebFeatureType.AddStructuralProperty("Heading", EdmPrimitiveTypeKind.String);
            model.AddElement(productWebFeatureType);

            var productReviewWebFeatures = new EdmNavigationPropertyInfo { Name = "Features", Target = productWebFeatureType, TargetMultiplicity = EdmMultiplicity.Many };
            var productWebFeatureReview = new EdmNavigationPropertyInfo { Name = "Review", Target = productReviewType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { productWebFeatureReviewId, productWebFeatureProductId }, PrincipalProperties = productReviewType.Key() };
            productWebFeatureType.AddBidirectionalNavigation(productWebFeatureReview, productReviewWebFeatures);

            var productPhotoWebFeatures = new EdmNavigationPropertyInfo { Name = "Features", Target = productWebFeatureType, TargetMultiplicity = EdmMultiplicity.Many };
            var productWebFeaturePhoto = new EdmNavigationPropertyInfo { Name = "Photo", Target = productPhotoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { productWebFeaturePhotoId, productWebFeatureProductId }, PrincipalProperties = productPhotoType.Key() };
            productWebFeatureType.AddBidirectionalNavigation(productWebFeaturePhoto, productPhotoWebFeatures);

            var computerType = new EdmEntityType("NS1", "Computer");
            computerType.AddKeys(computerType.AddStructuralProperty("ComputerId", EdmPrimitiveTypeKind.Int32, false));
            computerType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(computerType);

            var computerDetailType = new EdmEntityType("NS1", "ComputerDetail");
            computerDetailType.AddKeys(computerDetailType.AddStructuralProperty("ComputerDetailId", EdmPrimitiveTypeKind.Int32, false));
            computerDetailType.AddStructuralProperty("Model", EdmPrimitiveTypeKind.String);
            computerDetailType.AddStructuralProperty("Serial", EdmPrimitiveTypeKind.String);
            computerDetailType.AddStructuralProperty("Specifications", EdmPrimitiveTypeKind.String);
            computerDetailType.AddStructuralProperty("PurchaseDate", EdmPrimitiveTypeKind.DateTimeOffset);
            computerDetailType.AddStructuralProperty("Dimensions", dimensionsTypeReference);
            model.AddElement(computerDetailType);

            var computerDetailComputer = new EdmNavigationPropertyInfo { Name = "Computer", Target = computerType, TargetMultiplicity = EdmMultiplicity.One };
            var computerComputerDetail = new EdmNavigationPropertyInfo { Name = "ComputerDetail", Target = computerDetailType, TargetMultiplicity = EdmMultiplicity.One };
            computerType.AddBidirectionalNavigation(computerComputerDetail, computerDetailComputer);

            var driverType = new EdmEntityType("NS1", "Driver");
            driverType.AddKeys(driverType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isNullable: false, isUnicode: false)));
            driverType.AddStructuralProperty("BirthDate", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(driverType);

            var licenseType = new EdmEntityType("NS1", "License");
            var licenseDriverName = licenseType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isNullable: false, isUnicode: false));
            licenseType.AddKeys(licenseDriverName);
            licenseType.AddStructuralProperty("LicenseNumber", EdmPrimitiveTypeKind.String);
            licenseType.AddStructuralProperty("LicenseClass", EdmPrimitiveTypeKind.String);
            licenseType.AddStructuralProperty("Restrictions", EdmPrimitiveTypeKind.String);
            licenseType.AddStructuralProperty("ExpirationDate", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(licenseType);

            var driverLicense = new EdmNavigationPropertyInfo { Name = "License", Target = licenseType, TargetMultiplicity = EdmMultiplicity.One, };
            var licenseDriver = new EdmNavigationPropertyInfo { Name = "Driver", Target = driverType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { licenseDriverName }, PrincipalProperties = driverType.Key() };
            licenseType.AddBidirectionalNavigation(licenseDriver, driverLicense);

            #endregion

            model.AddDefaultContainerFixup("NS1");
            return model;
        }
Exemple #11
0
        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;
        }
Exemple #12
0
        public static IEdmModel AssociationIndependentEdm()
        {
            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 navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            return model;
        }
Exemple #13
0
        void BuildRelation(EdmModel model)
        {
            string parentName = string.Empty;
            string refrenceName = string.Empty;
            string parentColName = string.Empty;
            string refrenceColName = string.Empty;
            EdmEntityType parent = null;
            EdmEntityType refrence = null;
            EdmNavigationPropertyInfo parentNav = null;
            EdmNavigationPropertyInfo refrenceNav = null;
            List<IEdmStructuralProperty> principalProperties = null;
            List<IEdmStructuralProperty> dependentProperties = null;

            using (DbAccess db = new DbAccess(this.ConnectionString))
            {
                db.ExecuteReader(this.RelationCommand, (reader) =>
                {
                    if (parentName != reader["ParentName"].ToString() || refrenceName != reader["RefrencedName"].ToString())
                    {
                        if (!string.IsNullOrEmpty(refrenceName))
                        {
                            parentNav.PrincipalProperties = principalProperties;
                            parentNav.DependentProperties = dependentProperties;
                            //var np = parent.AddBidirectionalNavigation(refrenceNav, parentNav);
                            //var parentSet = model.EntityContainer.FindEntitySet(parentName) as EdmEntitySet;
                            //var referenceSet = model.EntityContainer.FindEntitySet(refrenceName) as EdmEntitySet;
                            //parentSet.AddNavigationTarget(np, referenceSet);
                            var np = refrence.AddBidirectionalNavigation(parentNav, refrenceNav);
                            var parentSet = model.EntityContainer.FindEntitySet(parentName) as EdmEntitySet;
                            var referenceSet = model.EntityContainer.FindEntitySet(refrenceName) as EdmEntitySet;
                            referenceSet.AddNavigationTarget(np, parentSet);

                        }
                        parentName = reader["ParentName"].ToString();
                        refrenceName = reader["RefrencedName"].ToString();
                        parent = model.FindDeclaredType(string.Format("ns.{0}", parentName)) as EdmEntityType;
                        refrence = model.FindDeclaredType(string.Format("ns.{0}", refrenceName)) as EdmEntityType;
                        parentNav = new EdmNavigationPropertyInfo();
                        parentNav.Name = parentName;
                        parentNav.TargetMultiplicity = EdmMultiplicity.Many;
                        parentNav.Target = parent;
                        refrenceNav = new EdmNavigationPropertyInfo();
                        refrenceNav.Name = refrenceName;
                        refrenceNav.TargetMultiplicity = EdmMultiplicity.Many;
                        //refrenceNav.Target = refrence;
                        principalProperties = new List<IEdmStructuralProperty>();
                        dependentProperties = new List<IEdmStructuralProperty>();
                    }
                    principalProperties.Add(parent.FindProperty(reader["ParentColumnName"].ToString()) as IEdmStructuralProperty);
                    dependentProperties.Add(refrence.FindProperty(reader["RefreancedColumnName"].ToString()) as IEdmStructuralProperty);
                }, null, CommandType.Text);
                if (refrenceNav != null)
                {
                    parentNav.PrincipalProperties = principalProperties;
                    parentNav.DependentProperties = dependentProperties;

                    //var np1 = parent.AddBidirectionalNavigation(refrenceNav, parentNav);
                    //var parentSet1 = model.EntityContainer.FindEntitySet(parentName) as EdmEntitySet;
                    //var referenceSet1 = model.EntityContainer.FindEntitySet(refrenceName) as EdmEntitySet;
                    //parentSet1.AddNavigationTarget(np1, referenceSet1);

                    var np1 = refrence.AddBidirectionalNavigation(parentNav, refrenceNav);
                    var parentSet1 = model.EntityContainer.FindEntitySet(parentName) as EdmEntitySet;
                    var referenceSet1 = model.EntityContainer.FindEntitySet(refrenceName) as EdmEntitySet;
                    referenceSet1.AddNavigationTarget(np1, parentSet1);
                }

            }
        }
        private void CreateNavigationProperty(EntityTypeConfiguration config)
        {
            Contract.Assert(config != null);

            EdmEntityType type = (EdmEntityType)(GetEdmType(config.ClrType));

            foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties)
            {
                EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo
                {
                    Name = navProp.Name,
                    TargetMultiplicity = navProp.Multiplicity,
                    Target = GetEdmType(navProp.RelatedClrType) as IEdmEntityType,
                    ContainsTarget = navProp.ContainsTarget,
                    OnDelete = navProp.OnDeleteAction
                };

                // Principal properties
                if (navProp.PrincipalProperties.Any())
                {
                    info.PrincipalProperties = GetDeclaringPropertyInfo(navProp.PrincipalProperties);
                }

                // Dependent properties
                if (navProp.DependentProperties.Any())
                {
                    info.DependentProperties = GetDeclaringPropertyInfo(navProp.DependentProperties);
                }

                IEdmProperty edmProperty = type.AddUnidirectionalNavigation(info);
                if (navProp.PropertyInfo != null && edmProperty != null)
                {
                    _properties[navProp.PropertyInfo] = edmProperty;
                }

                if (edmProperty != null && navProp.IsRestricted)
                {
                    _propertiesRestrictions[edmProperty] = new QueryableRestrictions(navProp);
                }
            }
        }
        public void EdmNavigationPropertyPrincipalPropertiesShouldReturnPrincipalProperties()
        {
            EdmEntityType type = new EdmEntityType("ns", "type");
            var key = type.AddStructuralProperty("Id1", EdmCoreModel.Instance.GetInt32(false));
            var notKey = type.AddStructuralProperty("Id2", EdmCoreModel.Instance.GetString(false));
            var p1 = type.AddStructuralProperty("p1", EdmCoreModel.Instance.GetInt32(false));
            var p2 = type.AddStructuralProperty("p1", EdmCoreModel.Instance.GetString(false));
            type.AddKeys(key);

            var navInfo1 = new EdmNavigationPropertyInfo()
            {
                Name = "nav",
                Target = type,
                TargetMultiplicity = EdmMultiplicity.Many,
                DependentProperties = new[] { p1, p2 },
                PrincipalProperties = new[] { key, notKey }
            };

            EdmNavigationProperty navProp = type.AddUnidirectionalNavigation(navInfo1);
            navProp.PrincipalProperties().Should().NotBeNull();
            navProp.PrincipalProperties().ShouldAllBeEquivalentTo(new[] { key, notKey });
        }
        private IEdmModel GetModel()
        {
            EdmModel myModel = new EdmModel();

            EdmComplexType shippingAddress = new EdmComplexType("MyNS", "ShippingAddress");
            shippingAddress.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            shippingAddress.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            shippingAddress.AddStructuralProperty("Region", EdmPrimitiveTypeKind.String);
            shippingAddress.AddStructuralProperty("PostalCode", EdmPrimitiveTypeKind.String);
            myModel.AddElement(shippingAddress);

            EdmComplexTypeReference shippingAddressReference = new EdmComplexTypeReference(shippingAddress, true);

            EdmEntityType order = new EdmEntityType("MyNS", "Order");
            order.AddStructuralProperty("ShippingAddress", shippingAddressReference);
            myModel.AddElement(order);

            EdmEntityType person = new EdmEntityType("MyNS", "Person");
            myModel.AddElement(person);

            customer = new EdmEntityType("MyNS", "Customer");
            customer.AddStructuralProperty("ContactName", EdmPrimitiveTypeKind.String);
            EdmNavigationPropertyInfo orderLinks = new EdmNavigationPropertyInfo
            {
                Name = "Orders",
                Target = order,
                TargetMultiplicity = EdmMultiplicity.Many
            };
            EdmNavigationPropertyInfo personLinks = new EdmNavigationPropertyInfo
            {
                Name = "Parent",
                Target = person,
                TargetMultiplicity = EdmMultiplicity.Many
            };
            customer.AddUnidirectionalNavigation(orderLinks);
            customer.AddUnidirectionalNavigation(personLinks);
            myModel.AddElement(customer);

            EdmEntityContainer container = new EdmEntityContainer("MyNS", "Example30");
            customers = container.AddEntitySet("Customers", customer);
            container.AddEntitySet("Orders", order);
            myModel.AddElement(container);

            return myModel;
        }
        private void CreateNavigationPropertiesForStockEntity(IEdmEntityType edmType, IEdmModel edmModel, EdmModel stockModel)
        {
            var stockType = (EdmEntityType)stockModel.FindType(edmType.FullName());

            foreach (var edmNavigation in edmType.DeclaredNavigationProperties())
            {
                var stockToRoleType = (EdmEntityType)stockModel.FindType(edmNavigation.ToEntityType().FullName());

                if (stockType.FindProperty(edmNavigation.Name) == null)
                {
                    Func<IEnumerable<IEdmStructuralProperty>, IEnumerable<IEdmStructuralProperty>> createDependentProperties = (dependentProps) =>
                    {
                        if (dependentProps == null)
                        {
                            return null;
                        }

                        var stockDependentProperties = new List<IEdmStructuralProperty>();
                        foreach (var dependentProperty in dependentProps)
                        {
                            var stockDepProp = edmNavigation.DependentProperties() != null ? stockType.FindProperty(dependentProperty.Name) : stockToRoleType.FindProperty(dependentProperty.Name);
                            stockDependentProperties.Add((IEdmStructuralProperty)stockDepProp);
                        }

                        return stockDependentProperties;
                    };

                    Func<IEdmReferentialConstraint, IEdmEntityType, IEnumerable<IEdmStructuralProperty>> createPrincipalProperties = (refConstraint, principalType) =>
                    {
                        if (refConstraint == null)
                        {
                            return null;
                        }

                        return refConstraint.PropertyPairs.Select(p => (IEdmStructuralProperty)principalType.FindProperty(p.PrincipalProperty.Name));
                    };

                    var propertyInfo = new EdmNavigationPropertyInfo()
                        {
                            Name = edmNavigation.Name,
                            Target = stockToRoleType,
                            TargetMultiplicity = edmNavigation.TargetMultiplicity(),
                            DependentProperties = createDependentProperties(edmNavigation.DependentProperties()),
                            PrincipalProperties = createPrincipalProperties(edmNavigation.ReferentialConstraint, stockToRoleType),
                            ContainsTarget = edmNavigation.ContainsTarget,
                            OnDelete = edmNavigation.OnDelete
                        };

                    bool bidirectional = edmNavigation.Partner != null && edmNavigation.ToEntityType().FindProperty(edmNavigation.Partner.Name) != null;
                    if (bidirectional)
                    {
                        var partnerInfo = new EdmNavigationPropertyInfo()
                        {
                            Name = edmNavigation.Partner.Name,
                            TargetMultiplicity = edmNavigation.Partner.TargetMultiplicity(), 
                            DependentProperties = createDependentProperties(edmNavigation.Partner.DependentProperties()),
                            PrincipalProperties = createPrincipalProperties(edmNavigation.Partner.ReferentialConstraint, stockType),
                            ContainsTarget = edmNavigation.Partner.ContainsTarget, 
                            OnDelete = edmNavigation.Partner.OnDelete
                        };

                        stockType.AddBidirectionalNavigation(propertyInfo, partnerInfo);
                    }
                    else
                    {
                        stockType.AddUnidirectionalNavigation(propertyInfo);
                    }
                }
            }
        }
        private IEdmModel GetModel()
        {
            EdmModel myModel = new EdmModel();

            EdmComplexType shippingAddress = new EdmComplexType("MyNS", "ShippingAddress");
            shippingAddress.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            shippingAddress.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            shippingAddress.AddStructuralProperty("Region", EdmPrimitiveTypeKind.String);
            shippingAddress.AddStructuralProperty("PostalCode", EdmPrimitiveTypeKind.String);
            myModel.AddElement(shippingAddress);

            EdmComplexTypeReference shippingAddressReference = new EdmComplexTypeReference(shippingAddress, true);

            EdmEntityType order = new EdmEntityType("MyNS", "Order");
            order.AddKeys(order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            order.AddStructuralProperty("ShippingAddress", shippingAddressReference);
            myModel.AddElement(order);

            EdmEntityType person = new EdmEntityType("MyNS", "Person");
            myModel.AddElement(person);

            customer = new EdmEntityType("MyNS", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            customer.AddStructuralProperty("ContactName", EdmPrimitiveTypeKind.String);
            EdmNavigationPropertyInfo orderLinks = new EdmNavigationPropertyInfo
            {
                Name = "Orders",
                Target = order,
                TargetMultiplicity = EdmMultiplicity.Many
            };
            EdmNavigationPropertyInfo personLinks = new EdmNavigationPropertyInfo
            {
                Name = "Parent",
                Target = person,
                TargetMultiplicity = EdmMultiplicity.Many
            };
            customer.AddUnidirectionalNavigation(orderLinks);
            customer.AddUnidirectionalNavigation(personLinks);
            myModel.AddElement(customer);

            EdmEntityType product = new EdmEntityType("MyNS", "Product");
            product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            myModel.AddElement(product);

            EdmEntityType productDetail = new EdmEntityType("MyNS", "ProductDetail");
            productDetail.AddKeys(productDetail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            productDetail.AddStructuralProperty("Detail", EdmPrimitiveTypeKind.String);
            myModel.AddElement(productDetail);

            product.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Details",
                Target = productDetail,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true,
            });

            EdmNavigationProperty favouriteProducts = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "FavouriteProducts",
                Target = product,
                TargetMultiplicity = EdmMultiplicity.Many,
                
            });
            EdmNavigationProperty productBeingViewed = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "ProductBeingViewed",
                Target = product,
                TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
            });

            EdmEntityContainer container = new EdmEntityContainer("MyNS", "Example30");
            customers = container.AddEntitySet("Customers", customer);
            container.AddEntitySet("Orders", order);
            EdmEntitySet products = container.AddEntitySet("Products", product);
            customers.AddNavigationTarget(favouriteProducts, products);
            customers.AddNavigationTarget(productBeingViewed, products);

            myModel.AddElement(container);

            return myModel;
        }
        private void CreateEntityTypeBody(EdmEntityType type, EntityTypeConfiguration config)
        {
            Contract.Assert(type != null);
            Contract.Assert(config != null);

            CreateStructuralTypeBody(type, config);
            IEnumerable<IEdmStructuralProperty> keys = config.Keys.Select(p => type.DeclaredProperties.OfType<IEdmStructuralProperty>().First(dp => dp.Name == p.Name));
            type.AddKeys(keys);

            foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties)
            {
                EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo
                {
                    Name = navProp.Name,
                    TargetMultiplicity = navProp.Multiplicity,
                    Target = GetEdmType(navProp.RelatedClrType) as IEdmEntityType,
                    ContainsTarget = navProp.ContainsTarget
                };
                IEdmProperty edmProperty = type.AddUnidirectionalNavigation(info);
                if (navProp.PropertyInfo != null && edmProperty != null)
                {
                    _properties[navProp.PropertyInfo] = edmProperty;
                }

                if (edmProperty != null && navProp.IsRestricted)
                {
                    _propertiesRestrictions[edmProperty] = new QueryableRestrictions(navProp);
                }
            }
        }
        private void CreateEntityTypeBody(EdmEntityType type, EntityTypeConfiguration config)
        {
            CreateStructuralTypeBody(type, config);
            IEdmStructuralProperty[] keys = config.Keys.Select(p => type.DeclaredProperties.OfType<IEdmStructuralProperty>().First(dp => dp.Name == p.Name)).ToArray();
            type.AddKeys(keys);

            foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties)
            {
                EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo();
                info.Name = navProp.Name;
                info.TargetMultiplicity = navProp.Multiplicity;
                info.Target = _types[navProp.RelatedClrType] as IEdmEntityType;
                //TODO: If target end has a multiplity of 1 this assumes the source end is 0..1.
                //      I think a better default multiplicity is *
                IEdmProperty edmProperty = type.AddUnidirectionalNavigation(info);
                if (navProp.PropertyInfo != null && edmProperty != null)
                {
                    _properties[navProp.PropertyInfo] = edmProperty;
                }

                if (edmProperty != null && navProp.IsRestricted)
                {
                    _propertiesRestrictions[edmProperty] = new QueryableRestrictions(navProp);
                }
            }
        }
 private static IEdmNavigationSource GetContainedEntitySet(EdmModel model, EdmEntityType type)
 {
     EdmEntitySet entitySet = GetEntitySet(model, type);
     var containedEntity = GetContainedEntityType(model);
     var navigationPropertyInfo = new EdmNavigationPropertyInfo()
     {
         Name = "nav",
         Target = containedEntity,
         TargetMultiplicity = EdmMultiplicity.Many, // todo: TargetMultiplicity info seems lost in V4
         ContainsTarget = true
     };
     EdmNavigationProperty navigationProperty = EdmNavigationProperty.CreateNavigationProperty(type, navigationPropertyInfo);
     type.AddUnidirectionalNavigation(navigationPropertyInfo);
     IEdmNavigationSource containedEntitySet = entitySet.FindNavigationTarget(navigationProperty);
     return containedEntitySet;
 }
        /// <summary>
        /// Creates two navigation properties representing an association between two entity types.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <param name="partnerInfo">Information to create the partner navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");
            EdmUtil.CheckArgumentNull(partnerInfo, "partnerInfo");
            EdmUtil.CheckArgumentNull(partnerInfo.Name, "partnerInfo.Name");
            EdmUtil.CheckArgumentNull(partnerInfo.Target, "partnerInfo.Target");

            EdmNavigationProperty end1 = new EdmNavigationProperty(
                partnerInfo.Target,
                propertyInfo.Name,
                CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"),
                propertyInfo.DependentProperties,
                propertyInfo.PrincipalProperties,
                propertyInfo.ContainsTarget,
                propertyInfo.OnDelete);

            EdmNavigationProperty end2 = new EdmNavigationProperty(
                propertyInfo.Target,
                partnerInfo.Name,
                CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"),
                partnerInfo.DependentProperties,
                partnerInfo.PrincipalProperties,
                partnerInfo.ContainsTarget,
                partnerInfo.OnDelete);

            end1.partner = end2;
            end2.partner = end1;
            return end1;
        }
Exemple #23
0
        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;
        }
        /// <summary>
        /// Creates a navigation property from the given information.
        /// </summary>
        /// <param name="declaringType">The type that declares this property.</param>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationProperty(IEdmEntityType declaringType, EdmNavigationPropertyInfo propertyInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");

            return new EdmNavigationProperty(
                declaringType,
                propertyInfo.Name,
                CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"),
                propertyInfo.DependentProperties,
                propertyInfo.PrincipalProperties,
                propertyInfo.ContainsTarget,
                propertyInfo.OnDelete);
        }
Exemple #25
0
        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;
        }
Exemple #26
0
        /// <summary>
        /// Creates and adds a unidirectional navigation property to this type.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public EdmNavigationProperty AddUnidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");

            EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationProperty(this, propertyInfo);

            this.AddProperty(property);
            return property;
        }
Exemple #27
0
        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;
        }
Exemple #28
0
        /// <summary>
        /// Creates and adds a navigation property to this type and adds its navigation partner to the navigation target type.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <param name="partnerInfo">Information to create the partner navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public EdmNavigationProperty AddBidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");

            EdmEntityType targetType = propertyInfo.Target as EdmEntityType;
            if (targetType == null)
            {
                throw new ArgumentException("propertyInfo.Target", Strings.Constructable_TargetMustBeStock(typeof(EdmEntityType).FullName));
            }

            EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo));

            this.AddProperty(property);
            targetType.AddProperty(property.Partner);
            return property;
        }
Exemple #29
0
        /// <summary>
        /// The puspose of this method is to make sure that some of the <paramref name="partnerInfo"/> fields are set to valid partner defaults.
        /// For example if <paramref name="partnerInfo"/>.Target is null, it will be set to this entity type. If <paramref name="partnerInfo"/>.TargetMultiplicity
        /// is unknown, it will be set to 0..1, etc.
        /// Whenever this method applies new values to <paramref name="partnerInfo"/>, it will return a copy of it (thus won't modify the original).
        /// If <paramref name="partnerInfo"/> is null, a new info object will be produced.
        /// </summary>
        /// <param name="propertyInfo">Primary navigation property info.</param>
        /// <param name="partnerInfo">Partner navigation property info. May be null.</param>
        /// <returns>Partner info.</returns>
        private EdmNavigationPropertyInfo FixUpDefaultPartnerInfo(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmNavigationPropertyInfo partnerInfoOverride = null;

            if (partnerInfo == null)
            {
                partnerInfo = partnerInfoOverride = new EdmNavigationPropertyInfo();
            }

            if (partnerInfo.Name == null)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.Name = (propertyInfo.Name ?? String.Empty) + "Partner";
            }

            if (partnerInfo.Target == null)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.Target = this;
            }

            if (partnerInfo.TargetMultiplicity == EdmMultiplicity.Unknown)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.TargetMultiplicity = EdmMultiplicity.ZeroOrOne;
            }

            return partnerInfoOverride ?? partnerInfo;
        }
Exemple #30
0
        /// <summary>
        /// Creates a navigation property from the given information.
        /// </summary>
        /// <param name="declaringType">The type that declares this property.</param>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationProperty(IEdmEntityType declaringType, EdmNavigationPropertyInfo propertyInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");

            return(new EdmNavigationProperty(
                       declaringType,
                       propertyInfo.Name,
                       CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"),
                       propertyInfo.DependentProperties,
                       propertyInfo.PrincipalProperties,
                       propertyInfo.ContainsTarget,
                       propertyInfo.OnDelete));
        }
Exemple #31
0
        private static void AddNavigationProperties(
            AssociationSet efAssociationSet,
            IDictionary<MetadataItem, IEdmElement> elementMap)
        {
            if (efAssociationSet.AssociationSetEnds.Count != 2)
            {
                return;
            }

            var efAssociation = efAssociationSet.ElementType;
            var navPropertyInfos = new EdmNavigationPropertyInfo[2];
            for (var i = 0; i < 2; i++)
            {
                var efEnd = efAssociation.AssociationEndMembers[i];
                var efEntityType = efEnd.GetEntityType();
                if (!elementMap.ContainsKey(efEntityType))
                {
                    continue;
                }

                var entityType = elementMap[efEntityType] as IEdmEntityType;
                var efNavProperty = efEntityType.NavigationProperties
                    .Where(np => np.FromEndMember == efEnd)
                    .SingleOrDefault();
                if (efNavProperty == null)
                {
                    continue;
                }

                var efTargetEntityType = efNavProperty
                    .ToEndMember.GetEntityType();
                if (!elementMap.ContainsKey(efTargetEntityType))
                {
                    continue;
                }

                var targetEntityType = elementMap[efTargetEntityType] as IEdmEntityType;
                navPropertyInfos[i] = new EdmNavigationPropertyInfo()
                {
                    ContainsTarget = false,
                    Name = efNavProperty.Name,
                    OnDelete = efEnd.DeleteBehavior == OperationAction.Cascade
                        ? EdmOnDeleteAction.Cascade : EdmOnDeleteAction.None,
                    Target = targetEntityType,
                    TargetMultiplicity = GetEdmMultiplicity(
                        efNavProperty.ToEndMember.RelationshipMultiplicity)
                };

                var constraint = efAssociation.Constraint;
                if (constraint != null && constraint.ToRole == efEnd)
                {
                    navPropertyInfos[i].DependentProperties = constraint.ToProperties
                        .Select(p => entityType.FindProperty(p.Name) as IEdmStructuralProperty);
                    navPropertyInfos[i].PrincipalProperties = constraint.FromProperties
                        .Select(p => targetEntityType.FindProperty(p.Name) as IEdmStructuralProperty);
                }
            }

            if (navPropertyInfos[0] == null && navPropertyInfos[1] != null)
            {
                var efEnd = efAssociation.AssociationEndMembers[1];
                var efEntityType = efEnd.GetEntityType();
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[1].Name) == null)
                {
                    entityType.AddUnidirectionalNavigation(navPropertyInfos[1]);
                }
            }

            if (navPropertyInfos[0] != null && navPropertyInfos[1] == null)
            {
                var efEnd = efAssociation.AssociationEndMembers[0];
                var efEntityType = efEnd.GetEntityType();
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
                {
                    entityType.AddUnidirectionalNavigation(navPropertyInfos[0]);
                }
            }

            if (navPropertyInfos[0] != null && navPropertyInfos[1] != null)
            {
                var efEnd = efAssociation.AssociationEndMembers[0];
                var efEntityType = efEnd.GetEntityType();
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
                {
                    entityType.AddBidirectionalNavigation(
                        navPropertyInfos[0], navPropertyInfos[1]);
                }
            }
        }
Exemple #32
0
		private void DoIt(NavigationPropertyConfiguration navProp, EdmEntityType type)
		{
			foreach (var dependentProperty in navProp.DependentProperties)
			{
				if (dependentProperty.GetConfiguration(_configurations).IsIgnored)
				{
					navProp.IsIgnored = true;
					return;
				}
			}
			if (navProp.IsIgnored)
			{
				return;
			}
			EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo
			{
				Name = navProp.Name,
				TargetMultiplicity = navProp.Multiplicity,
				Target = GetEdmType(navProp.RelatedClrType) as IEdmEntityType,
				ContainsTarget = navProp.ContainsTarget,
				OnDelete = navProp.OnDeleteAction
			};

			// Principal properties
			if (navProp.PrincipalProperties.Any())
			{
				info.PrincipalProperties = GetDeclaringPropertyInfo(navProp.PrincipalProperties);
			}

			// Dependent properties
			if (navProp.DependentProperties.Any())
			{
				info.DependentProperties = GetDeclaringPropertyInfo(navProp.DependentProperties);
			}

			IEdmProperty edmProperty = type.AddUnidirectionalNavigation(info);
			if (navProp.PropertyInfo != null && edmProperty != null)
			{
				_properties[navProp.PropertyInfo] = edmProperty;
			}

			if (edmProperty != null && navProp.IsRestricted)
			{
				_propertiesRestrictions[edmProperty] = new QueryableRestrictions(navProp);
			}
		}