public Key ( KeyType keyType ) : |
||
keyType | KeyType | |
Результат |
protected virtual void AutoMap() { Type type = typeof(T); bool keyFound = Properties.Any(p => p.KeyType != KeyType.NotAKey); foreach (var propertyInfo in type.GetProperties()) { if (Properties.Any(p => p.Name.Equals(propertyInfo.Name, StringComparison.InvariantCultureIgnoreCase))) { continue; } PropertyMap map = Map(propertyInfo); if (!keyFound && map.PropertyInfo.Name.EndsWith("id", true, CultureInfo.InvariantCulture)) { if (map.PropertyInfo.PropertyType == typeof(int) || map.PropertyInfo.PropertyType == typeof(int?)) { map.Key(KeyType.Identity); } else if (map.PropertyInfo.PropertyType == typeof(Guid) || map.PropertyInfo.PropertyType == typeof(Guid?)) { map.Key(KeyType.Guid); } else { map.Key(KeyType.Assigned); } keyFound = true; } } }
protected virtual void AutoMap(Func <Type, PropertyInfo, bool> canMap) { Type type = typeof(T); bool hasDefinedKey = Properties.Any(p => p.KeyType != KeyType.NotAKey); PropertyMap keyMap = null; foreach (var propertyInfo in type.GetProperties()) { if (Properties.Any(p => p.Name.Equals(propertyInfo.Name, StringComparison.InvariantCultureIgnoreCase))) { continue; } if ((canMap != null && !canMap(type, propertyInfo))) { continue; } PropertyMap map = Map(propertyInfo); if (!hasDefinedKey) { if (IsAttributeExist(map.PropertyInfo, typeof(KeyAttribute))) { keyMap = map; } } } if (keyMap != null) { keyMap.Key(PropertyTypeKeyTypeMapping.ContainsKey(keyMap.PropertyInfo.PropertyType) ? PropertyTypeKeyTypeMapping[keyMap.PropertyInfo.PropertyType] : KeyType.Assigned); } }
protected virtual void AutoMap(Func <Type, PropertyInfo, bool> canMap) { Type type = typeof(T); bool hasDefinedKey = Properties.Any(p => p.KeyType != KeyType.NotAKey); PropertyMap keyMap = null; foreach (var propertyInfo in type.GetProperties()) { if (Properties.Any(p => p.Name.Equals(propertyInfo.Name, StringComparison.InvariantCultureIgnoreCase))) { continue; } if ((canMap != null && !canMap(type, propertyInfo))) { continue; } PropertyMap map = Map(propertyInfo); if (!hasDefinedKey) { if (string.Equals(map.PropertyInfo.Name, "id", StringComparison.InvariantCultureIgnoreCase)) { keyMap = map; } if (keyMap == null && map.PropertyInfo.Name.EndsWith("id", true, CultureInfo.InvariantCulture)) { keyMap = map; } var KeyAttr = propertyInfo.GetCustomAttributes(typeof(KeyAttribute), true).ToArray(); if (KeyAttr.Length > 0) { keyMap = map; } } } if (keyMap != null) { keyMap.Key(PropertyTypeKeyTypeMapping.ContainsKey(keyMap.PropertyInfo.PropertyType) ? PropertyTypeKeyTypeMapping[keyMap.PropertyInfo.PropertyType] : KeyType.Assigned); } }