Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create migration script #112

Open
truthz03 opened this issue Nov 22, 2024 · 2 comments
Open

Unable to create migration script #112

truthz03 opened this issue Nov 22, 2024 · 2 comments

Comments

@truthz03
Copy link

truthz03 commented Nov 22, 2024

Hi,

I'm using Net8 with Laraue.EfCoreTriggers.SqlServer 8.1.2

if I create my code first migration script with Add-Migration AddTrigger -OutputDir Migrations -verbose the first time including triggers, everyting is working.

But if I create my first migration script without triggers, add

modelBuilder.Entity<ObjectsecurityAttachmentModel>()
    .AfterDelete(trigger => trigger
        .Action(action => action
            .Delete<FileDataModel>((e, a) => e.Old.FileId == a.Id)));

after that und create a second step migration script I get the following error:

System.InvalidOperationException: DbSet<System.Collections.Generic.Dictionary2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]> should be added to the DbContext at Laraue.EfCoreTriggers.Common.SqlGeneration.EfCoreDbSchemaRetriever.GetEntityType(Type type) at Laraue.EfCoreTriggers.Common.SqlGeneration.EfCoreDbSchemaRetriever.GetTableSchemaName(Type entity) at Laraue.EfCoreTriggers.Common.SqlGeneration.SqlGenerator.GetSchemaPrefixSql(Type entity) at Laraue.EfCoreTriggers.SqlServer.SqlServerTriggerVisitor.GenerateDeleteTriggerSql(String triggerName, IEntityType entityType) at Laraue.EfCoreTriggers.Common.Migrations.MigrationsExtensions.AddDeleteTriggerSqlMigration(ITriggerVisitor triggerVisitor, IList1 list, IAnnotation annotation, IEntityType entityType)
at Laraue.EfCoreTriggers.Common.Migrations.TriggerModelDiffer.AddTriggerOperations(IEnumerable1 operations, IRelationalModel source, IRelationalModel target) at Laraue.EfCoreTriggers.Common.Migrations.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target) at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_01.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

Did I do anything wrong? Isn't it possible to add triggers after already having other migration scripts?

@win7user10
Copy link
Owner

Hi. Could you please provide the ObjectsecurityAttachmentModel definition to repoduce the case?

@Xriuk
Copy link

Xriuk commented Nov 27, 2024

I'm having the same problem, when I add a self-referencing relationship (a hierarchy of entities) I get the same exception:

DbSet<System.Collections.Generic.Dictionary`2[System.String,System.Object]> should be added to the DbContext
   at Laraue.EfCoreTriggers.Common.SqlGeneration.EfCoreDbSchemaRetriever.GetEntityType(Type type)
   at Laraue.EfCoreTriggers.Common.SqlGeneration.EfCoreDbSchemaRetriever.GetTableSchemaName(Type entity)
   at Laraue.EfCoreTriggers.Common.SqlGeneration.SqlGenerator.GetSchemaPrefixSql(Type entity)
   at Laraue.EfCoreTriggers.SqlServer.SqlServerTriggerVisitor.GenerateDeleteTriggerSql(String triggerName, IEntityType entityType)
   at Laraue.EfCoreTriggers.Common.Migrations.MigrationsExtensions.AddDeleteTriggerSqlMigration(ITriggerVisitor triggerVisitor, IList`1 list, IAnnotation annotation, IEntityType entityType)
   at Laraue.EfCoreTriggers.Common.Migrations.TriggerModelDiffer.AddTriggerOperations(IEnumerable`1 operations, IRelationalModel source, IRelationalModel target)
   at Laraue.EfCoreTriggers.Common.Migrations.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

The System.Collections.Generic.Dictionary`2[System.String,System.Object] part could be referring to some internal join-entities to handle many-to-one, many-to-many relationships.

My entity looks similar to this:

public class Entity{
    public Guid Id {get; set;}

    public Entity? ParentEntity {get; set;}

    public ICollection<Entity> NestedEntities {get; set;}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants