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)); }
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)); }
private static IEnumerable <PropertyDescriptor> SortClrPropertyByOrder(OeEdmModelMetadataProvider metadataProvider, IEnumerable <PropertyDescriptor> clrProperties) { var propertyList = new List <Tuple <PropertyDescriptor, int> >(2); foreach (PropertyDescriptor clrProperty in clrProperties) { int order = metadataProvider.GetOrder(clrProperty); if (order == -1) { return(clrProperties); } propertyList.Add(new Tuple <PropertyDescriptor, int>(clrProperty, order)); } return(propertyList.OrderBy(t => t.Item2).Select(t => t.Item1)); }
private void AddKeys() { if (_keyProperties.Count == 0) { PropertyDescriptorCollection clrPoperties = TypeDescriptor.GetProperties(_clrType); PropertyDescriptor key = clrPoperties.Find("id", true); if (key != null) { var edmProperty = (EdmStructuralProperty)_edmType.Properties().Single(p => p.Name == key.Name); _keyProperties.Add(new KeyValuePair <PropertyDescriptor, EdmStructuralProperty>(key, edmProperty)); } else { key = clrPoperties.Find(_clrType.Name + "id", true); if (key == null) { throw new InvalidOperationException("Key property not matching"); } var edmProperty = (EdmStructuralProperty)_edmType.Properties().Single(p => p.Name == key.Name); _keyProperties.Add(new KeyValuePair <PropertyDescriptor, EdmStructuralProperty>(key, edmProperty)); } } if (_keyProperties.Count == 1) { _edmType.AddKeys(_keyProperties[0].Value); return; } var keys = new Tuple <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 Tuple <EdmStructuralProperty, int>(_keyProperties[i].Value, order); } _edmType.AddKeys(keys.OrderBy(p => p.Item2).Select(p => p.Item1)); }
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)); }