Skip to content

Commit

Permalink
Update to EF8
Browse files Browse the repository at this point in the history
Resolves #216
  • Loading branch information
bricelam committed Nov 3, 2023
1 parent 9903710 commit 3f3fabb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<EFCoreVersion>[7.0.2,8.0.0)</EFCoreVersion>
<MicrosoftExtensionsVersion>7.0.0</MicrosoftExtensionsVersion>
<EFCoreVersion>[8.0.0-rc.2.23480.1,9.0.0)</EFCoreVersion>
<MicrosoftExtensionsVersion>8.0.0-rc.2.23479.6</MicrosoftExtensionsVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions EFCore.NamingConventions.Test/NameRewritingConventionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,21 @@ public void Owned_entity_withs_OwnsMany()
.GetColumnName(StoreObjectIdentifier.Create(ownedEntityType, StoreObjectType.Table)!.Value));
}

[Fact]
public void Complex_property()
{
var model = BuildModel(b =>
b.Entity<Waypoint>().ComplexProperty(w => w.Location));

var entityType = model.FindEntityType(typeof(Waypoint))!;
var complexType = entityType.FindComplexProperty("Location")!.ComplexType;

Assert.Equal("location_longitude", complexType.FindProperty("Longitude")!
.GetColumnName(StoreObjectIdentifier.Create(entityType, StoreObjectType.Table)!.Value));
Assert.Equal("location_latitude", complexType.FindProperty("Latitude")!
.GetColumnName(StoreObjectIdentifier.Create(entityType, StoreObjectType.Table)!.Value));
}

[Fact]
public void Not_mapped_to_table()
{
Expand Down Expand Up @@ -658,4 +673,16 @@ public class Owned
{
public int OwnedProperty { get; set; }
}

public class Waypoint
{
public int Id { get; set; }
public required Location Location { get; set; }
}

public class Location
{
public double Longitude { get; set; }
public double Latitude { get; set; }
}
}
4 changes: 2 additions & 2 deletions EFCore.NamingConventions/EFCore.NamingConventions.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<VersionPrefix>7.0.2</VersionPrefix>
<TargetFramework>net8.0</TargetFramework>
<VersionPrefix>8.0.0</VersionPrefix>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../EFCore.NamingConventions.snk</AssemblyOriginatorKeyFile>
Expand Down
6 changes: 3 additions & 3 deletions EFCore.NamingConventions/Internal/NameRewritingConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConven
private void RewriteColumnName(IConventionPropertyBuilder propertyBuilder)
{
var property = propertyBuilder.Metadata;
var entityType = (IConventionEntityType)property.DeclaringType;
var structuralType = property.DeclaringType;

// Remove any previous setting of the column name we may have done, so we can get the default recalculated below.
property.Builder.HasNoAnnotation(RelationalAnnotationNames.ColumnName);

// TODO: The following is a temporary hack. We should probably just always set the relational override below,
// but https://github.com/dotnet/efcore/pull/23834
var baseColumnName = StoreObjectIdentifier.Create(entityType, StoreObjectType.Table) is { } tableIdentifier
var baseColumnName = StoreObjectIdentifier.Create(structuralType, StoreObjectType.Table) is { } tableIdentifier
? property.GetDefaultColumnName(tableIdentifier)
: property.GetDefaultColumnName();
if (baseColumnName is not null)
Expand All @@ -310,7 +310,7 @@ private void RewriteColumnName(IConventionPropertyBuilder propertyBuilder)

foreach (var storeObjectType in _storeObjectTypes)
{
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
var identifier = StoreObjectIdentifier.Create(structuralType, storeObjectType);
if (identifier is null)
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.100-rc.2.23502.2",
"rollForward": "latestMajor",
"allowPrerelease": true
}
Expand Down

0 comments on commit 3f3fabb

Please sign in to comment.