You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Owned]
public class ChangeInfo
{
[MaxLength(256)]
public required string By { get; set; }
public DateTimeOffset At { get; set; }
}
And an entity which uses this type for creation and modification info:
public class MyEntity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
...
public required ChangeInfo Created { get; set; }
public required ChangeInfo Modified { get; set; }
...
}
In Program.cs I try to create metadata for a DbContext which has a DbSet of this entity:
if (args.Length > 0 && args[0].Contains("metadata"))
{
// Generate breeze metadata and exit.
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var context = services.GetRequiredService<MyDbContext>();
var persistanceManager = new MyDbPersistenceManager(context);
var metadata = persistanceManager.Metadata();
Console.Out.WriteLine(metadata);
}
return;
}
But it fails with an ArgumentException which says "An item with the same key has already been added. Key: ChangeInfo".
I can reproduce the same exception with the following code:
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var context = services.GetRequiredService<MyDbContext>();
var complexTypes = context.Model.GetEntityTypes()
.Where(et => et.IsOwned())
.Select(et => et.ClrType.Name).ToList();
var map = complexTypes.ToDictionary(mt => mt);
}
This is quite similar to what happens in the MetadataBuilder from line 26 to 28. In this case the complexTypes list will contain two MetaType instances with a ShortName of 'ChangeInfo' and so the call complexTypes.ToDictionary(mt => mt.ShortName) throws the exception mentioned above.
I am using:
Breeze.AspNetCore.NetCore 7.0.2
Breeze.Persistence.EFCore 7.0.2
Microsoft.EntityFrameworkCore.Tools 7.0.4
Microsoft.EntityFrameworkCore.SqlServer 7.0.4
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
apircher
changed the title
Generation of metadata fails when an entity has two owned properties with the same type.
Generation of metadata fails when an entity has two properties with the same owned type.
Mar 20, 2023
I have an owned type called ChangeInfo:
And an entity which uses this type for creation and modification info:
In Program.cs I try to create metadata for a DbContext which has a DbSet of this entity:
But it fails with an ArgumentException which says "An item with the same key has already been added. Key: ChangeInfo".
The problem seems to occur in Breeze.Persistence.EFCore.MetadataBuilder in line 31.
I can reproduce the same exception with the following code:
This is quite similar to what happens in the MetadataBuilder from line 26 to 28. In this case the complexTypes list will contain two MetaType instances with a ShortName of 'ChangeInfo' and so the call
complexTypes.ToDictionary(mt => mt.ShortName)
throws the exception mentioned above.I am using:
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: