Esempio n. 1
0
        private void AddKeys()
        {
            if (_keyProperties.Count == 0)
            {
                PropertyInfo key = ClrType.GetPropertyIgnoreCase("id");
                if (key != null)
                {
                    var edmProperty = (EdmStructuralProperty)EdmType.GetPropertyIgnoreCase(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.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));
        }
Esempio n. 2
0
 private void AddDbQueryKeys()
 {
     EdmType.AddKeys(EdmType.StructuralProperties());
 }