According to convention, if the property is the primary key and it is an integer, make it the identity column. This wasn't being set by default

pull/131/head
Christopher Jolly 3 years ago
parent 4eb1b0cdd8
commit 0bc5d04759

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
@ -32,7 +33,7 @@ namespace EntityFrameworkCore.Jet.Metadata.Internal
: base(dependencies)
{
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@ -86,6 +87,26 @@ namespace EntityFrameworkCore.Jet.Metadata.Internal
JetAnnotationNames.Identity,
string.Format(CultureInfo.InvariantCulture, "{0}, {1}", seed ?? 1, increment ?? 1));
}
else
{
property = column.PropertyMappings.First().Property;
// Only return auto increment for integer single column primary key
var primaryKey = property.DeclaringEntityType.FindPrimaryKey();
if (primaryKey != null
&& primaryKey.Properties.Count == 1
&& primaryKey.Properties[0] == property
&& property.ValueGenerated == ValueGenerated.OnAdd
&& property.ClrType.UnwrapNullableType().IsInteger()
&& !HasConverter(property))
{
yield return new Annotation(
JetAnnotationNames.Identity,
string.Format(CultureInfo.InvariantCulture, "{0}, {1}", 1, 1));
}
}
}
private static bool HasConverter(IProperty property)
=> (property.GetValueConverter() ?? property.FindTypeMapping()?.Converter) != null;
}
}
Loading…
Cancel
Save