Add code to add a "MatchSimple" annotation to a foreign key

pull/144/head
Christopher Jolly 2 years ago
parent 5b591b73fd
commit 76408338e0

@ -0,0 +1,27 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Runtime.CompilerServices;
using EntityFrameworkCore.Jet.Metadata;
using EntityFrameworkCore.Jet.Metadata.Internal;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using EntityFrameworkCore.Jet.Utilities;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Jet specific extension methods for <see cref="ModelBuilder" />.
/// </summary>
public static class JetReferenceCollectionExtensions
{
public static ReferenceCollectionBuilder<TPrincipalEntity, TDependentEntity> MatchSimple<TPrincipalEntity, TDependentEntity>(this ReferenceCollectionBuilder<TPrincipalEntity, TDependentEntity> referenceCollectionBuilder)
where TPrincipalEntity : class
where TDependentEntity : class
{
referenceCollectionBuilder.Metadata.SetAnnotation(JetAnnotationNames.Prefix + "MatchSimple", "MatchSimple");
return referenceCollectionBuilder;
}
}
}

@ -6,6 +6,7 @@ using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.DependencyInjection;
namespace EntityFrameworkCore.Jet.Metadata.Internal
@ -120,6 +121,19 @@ namespace EntityFrameworkCore.Jet.Metadata.Internal
}
}
public override IEnumerable<IAnnotation> For(IForeignKeyConstraint foreignKey, bool designTime)
{
var table = StoreObjectIdentifier.Table(foreignKey.Table.Name, foreignKey.Table.Schema);
foreach (var fk in foreignKey.MappedForeignKeys)
{
if (fk.FindAnnotation(JetAnnotationNames.Prefix + "MatchSimple") != null)
{
yield return new Annotation(JetAnnotationNames.Prefix + "MatchSimple", "MatchSimple");
}
}
}
private static bool HasConverter(IProperty property)
=> (property.GetValueConverter() ?? property.FindTypeMapping()?.Converter) != null;
}

Loading…
Cancel
Save