Пример #1
0
        private void AddKeys()
        {
            if (_keyProperties.Count == 0)
            {
                PropertyInfo?key = ClrType.GetPropertyIgnoreCaseOrNull("id");
                if (key != null)
                {
                    var edmProperty = (EdmStructuralProperty)EdmType.GetPropertyIgnoreCase(key.Name);
                    _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
                }
                else
                {
                    key = ClrType.GetPropertyIgnoreCaseOrNull(ClrType.Name + "id");
                    if (key == null)
                    {
                        key = ClrType.GetProperties().Where(prop => prop.Name == "UserId").First();
                    }
                    if (key == null)
                    {
                        //Special Handling IdentityUser

                        if (EdmType.Key().Any() || ClrType.IsAbstract)
                        {
                            return;
                        }

                        throw new InvalidOperationException("Key property not matching");
                    }

                    var edmProperty = (EdmStructuralProperty)EdmType.GetPropertyIgnoreCase(key.Name);
                    _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
                }
            }

            if (_keyProperties.Count == 1)
            {
                EdmType.AddKeys(_keyProperties[0].Value);
                return;
            }

            var keys = new ValueTuple <EdmStructuralProperty, int> [_keyProperties.Count];

            for (int i = 0; i < _keyProperties.Count; i++)
            {
                int order = _metadataProvider.GetOrder(_keyProperties[i].Key);
                if (order == -1)
                {
                    EdmType.AddKeys(_keyProperties.Select(p => p.Value));
                    return;
                }

                keys[i] = new ValueTuple <EdmStructuralProperty, int>(_keyProperties[i].Value, order);
            }
            EdmType.AddKeys(keys.OrderBy(p => p.Item2).Select(p => p.Item1));
        }
Пример #2
0
        private void AddKeys()
        {
            if (_keyProperties.Count == 0)
            {
                PropertyInfo key = _clrType.GetPropertyIgnoreCase("id");
                if (key != null)
                {
                    var edmProperty = (EdmStructuralProperty)_edmType.Properties().Single(p => p.Name == key.Name);
                    _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
                }
                else
                {
                    key = _clrType.GetPropertyIgnoreCase(_clrType.Name + "id");
                    if (key == null)
                    {
                        if (EdmType.Key().Any() || _clrType.IsAbstract)
                        {
                            return;
                        }

                        throw new InvalidOperationException("Key property not matching");
                    }

                    var edmProperty = (EdmStructuralProperty)_edmType.Properties().Single(p => p.Name == key.Name);
                    _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
                }
            }

            if (_keyProperties.Count == 1)
            {
                _edmType.AddKeys(_keyProperties[0].Value);
                return;
            }

            var keys = new ValueTuple <EdmStructuralProperty, int> [_keyProperties.Count];

            for (int i = 0; i < _keyProperties.Count; i++)
            {
                int order = _metadataProvider.GetOrder(_keyProperties[i].Key);
                if (order == -1)
                {
                    _edmType.AddKeys(_keyProperties.Select(p => p.Value));
                    return;
                }

                keys[i] = new ValueTuple <EdmStructuralProperty, int>(_keyProperties[i].Value, order);
            }
            _edmType.AddKeys(keys.OrderBy(p => p.Item2).Select(p => p.Item1));
        }
Пример #3
0
        private void AddKeys()
        {
            if (_keyProperties.Count == 0)
            {
                PropertyInfo?key = OeModelBuilderHelper.GetConventionalKeyProperty(ClrType);
                if (key == null)
                {
                    if (EdmType.Key().Any() || ClrType.IsAbstract)
                    {
                        return;
                    }

                    throw new InvalidOperationException("Key property not matching");
                }

                var edmProperty = (EdmStructuralProperty)EdmType.GetPropertyIgnoreCase(key.Name);
                _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
            }

            if (_keyProperties.Count == 1)
            {
                EdmType.AddKeys(_keyProperties[0].Value);
                return;
            }

            var keys = new ValueTuple <EdmStructuralProperty, int> [_keyProperties.Count];

            for (int i = 0; i < _keyProperties.Count; i++)
            {
                int order = _metadataProvider.GetOrder(_keyProperties[i].Key);
                if (order == -1)
                {
                    EdmType.AddKeys(_keyProperties.Select(p => p.Value));
                    return;
                }

                keys[i] = new ValueTuple <EdmStructuralProperty, int>(_keyProperties[i].Value, order);
            }
            EdmType.AddKeys(keys.OrderBy(p => p.Item2).Select(p => p.Item1));
        }