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;
}
}
}