Eigenschaften, die im Schattenstaat erstellt werden, obwohl Eigentum im Unternehmen vorhanden ist [Duplikat]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Eigenschaften, die im Schattenstaat erstellt werden, obwohl Eigentum im Unternehmen vorhanden ist [Duplikat]

Post by Anonymous »

Ich habe Probleme mit Efcore. Ich habe einige Einheiten mit Navigationseigenschaften erstellt. Ich werde unten ein Beispiel unten veröffentlichen (SystemLicense und Kunde). Diese haben eine Weile gut gearbeitet, aber ich musste die Ondelete-Actions so ändern, dass sie dem tatsächlichen Workflow entspricht. Also habe ich die Beziehungen mit Fluent konfiguriert. Das Problem: Bei der Erstellung einer neuen Migration, um diese Änderungen widerzuspiegeln, werden mehrere Eigenschaften im Schattenzustand erzeugt. In diesem Beispiel schafft es CustomerID als CustomerID1, obwohl es soweit ich sehen kann. Dies ist das vollständige Migrationsprotokoll (findet für einige Modelle statt, ich habe andere Protokolleinträge in Bezug auf andere Modelle entfernt) < /p>
Build started...
Build succeeded.
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]
Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
warn: 23/09/2025 10:06:21.145 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure)
The foreign key property 'ModuleLicense.UserIdentityId1' was created in shadow state because a conflicting property with the simple name 'UserIdentityId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.
The property 'Customer.ApplicationUserId' was created in shadow state because there are no eligible CLR members with a matching name.
dbug: 23/09/2025 10:06:21.167 CoreEventId.ShadowPropertyCreated[10600] (Microsoft.EntityFrameworkCore.Model.Validation)
warn: Microsoft.EntityFrameworkCore.Model.Validation[10625]
warn: 23/09/2025 10:06:21.171 CoreEventId.ShadowForeignKeyPropertyCreated[10625] (Microsoft.EntityFrameworkCore.Model.Validation)
The property 'ApplicationUserRole.ApplicationRoleId' was created in shadow state because there are no eligible CLR members with a matching name.
dbug: 23/09/2025 10:06:21.168 CoreEventId.ShadowPropertyCreated[10600] (Microsoft.EntityFrameworkCore.Model.Validation)
warn: 23/09/2025 10:06:21.171 CoreEventId.ShadowForeignKeyPropertyCreated[10625] (Microsoft.EntityFrameworkCore.Model.Validation)
warn: Microsoft.EntityFrameworkCore.Model.Validation[10625]
The foreign key property 'SystemLicense.CustomerId1' was created in shadow state because a conflicting property with the simple name 'CustomerId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.
The foreign key property 'SystemLicense.CustomerId1' was created in shadow state because a conflicting property with the simple name 'CustomerId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.
dbug: 23/09/2025 10:06:21.280 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)
Entity Framework Core 8.0.15 initialized 'LicenseDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL:8.0.11+52a6b9f2ddd23fcabd1c673b4a2e273495129481' with options: SensitiveDataLoggingEnabled
warn: Microsoft.EntityFrameworkCore.Model.Validation[10625]
dbug: 23/09/2025 10:06:21.357 CoreEventId.ShadowPropertyCreated[10600] (Microsoft.EntityFrameworkCore.Model.Validation)
dbug: 23/09/2025 10:06:21.357 CoreEventId.ShadowPropertyCreated[10600] (Microsoft.EntityFrameworkCore.Model.Validation)
warn: 23/09/2025 10:06:21.363 CoreEventId.ShadowForeignKeyPropertyCreated[10625] (Microsoft.EntityFrameworkCore.Model.Validation)
warn: 23/09/2025 10:06:21.362 CoreEventId.ShadowForeignKeyPropertyCreated[10625] (Microsoft.EntityFrameworkCore.Model.Validation)
The foreign key property 'SystemLicense.CustomerId1' was created in shadow state because a conflicting property with the simple name 'CustomerId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.
The foreign key property 'SystemLicense.CustomerId1' was created in shadow state because a conflicting property with the simple name 'CustomerId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.
warn: Microsoft.EntityFrameworkCore.Model.Validation[10625]
The foreign key property 'SystemLicense.CustomerId1' was created in shadow state because a conflicting property with the simple name 'CustomerId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.
dbug: 23/09/2025 10:06:21.716 CoreEventId.ContextDisposed[10407] (Microsoft.EntityFrameworkCore.Infrastructure)
'LicenseDbContext' disposed.
Done. To undo this action, use 'ef migrations remove'
< /code>
Dies sind die Klassendefinitionen von Kunden und SystemLicense sowie die Konfiguration der Fremdschlüssel: < /p>
customer.cs:
using VT.license.Core.Entities.Identity;
using VT.license.Core.Interfaces;

namespace VT.license.Core.Entities;

public class Customer : IHasId
{
// Properties
public required string Name { get; set; } = "Mustermann GmbH";
public ulong? CustomerReference { get; set; }
public string? DistributorReference { get; set; }
public Guid? DefaultDistributorId { get; set; } = null;
public string? Email { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public string? City { get; set; }
public string? ZipCode { get; set; }
public string? State { get; set; }
public string? ContactPerson { get; set; }
public string? ContactEmail { get; set; }
public string? ContactPhone { get; set; }
public DateTime CreatedAt { get; init; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; }

public bool MaintainerPermissionsApproved { get; set; } = false;

public Guid
MaintainerId { get; set; } // Reference to the ApplicationUser who maintains this customer

// Navigation properties
public ApplicationUser? Maintainer { get; set; }
public List SystemLicenses { get; init; } = [];
public Distributor? DefaultDistributor { get; set; }
public Guid Id { get; set; }
}
< /code>
systemLicense.cs:
using VT.license.Core.Enums;
using VT.license.Core.Interfaces;

namespace VT.license.Core.Entities;

public class SystemLicense : IHasId
{
// Properties
public string? LicenseName { get; set; }
public DateTime MinimumTerm { get; set; }
public DbInformation? DbInformation { get; set; }
public LicenseStatusEnum LicenseStatus { get; set; }
public SystemLicenseMetadata? Metadata { get; set; }
public Guid? ArticleId { get; set; }
public Guid? DistributorId { get; set; }
public Guid CustomerId { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; }
public ChannelTypeEnum ReleaseChannel { get; set; } = ChannelTypeEnum.ProductionChannel;

// Navigation properties
public Distributor? Distributor { get; set; } // No Distributor = visoma GmbH
public Customer Customer { get; set; } = null!;
public Article? SystemArticle { get; set; } = null!;
public List? Licenses { get; set; } = [];

public Guid Id { get; set; }
}
< /code>
Konfiguration: < /p>
using Microsoft.EntityFrameworkCore;
using VT.license.Core.Entities;
using VT.license.Core.Entities.UserIdentity;

namespace VT.license.Infrastructure.DatabaseContext;

///
/// Configures the relationships between entities.
///
public class RelationshipConfigurationModelBuilder
{
///
/// Applies the relationships between the entities in the database context.
///
///
public void Apply(ref ModelBuilder modelBuilder)
{
#region Foreign Key Constraints & Delete Behavior

#region Article

modelBuilder.Entity().HasOne(a => a.Category).WithMany()
.HasForeignKey(a => a.CategoryId).OnDelete(DeleteBehavior.SetNull);

#endregion

#region Customer

modelBuilder.Entity()
.HasOne(c => c.Maintainer) // Fix: Use navigation property, not Guid
.WithMany().HasForeignKey(c => c.MaintainerId)
.OnDelete(DeleteBehavior.Restrict); // Optional: Specify delete behavior

modelBuilder.Entity().HasOne(c => c.DefaultDistributor).WithMany()
.HasForeignKey(c => c.DefaultDistributorId).OnDelete(DeleteBehavior.SetNull);

#endregion

#region Invoice & InvoiceItem

modelBuilder.Entity().HasOne(ii => ii.Article).WithMany()
.HasForeignKey(ii => ii.ArticleId).OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity().HasOne(ii => ii.Invoice).WithMany(i => i.Items)
.HasForeignKey(ii => ii.InvoiceId).OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity().HasOne(i => i.Customer).WithMany()
.HasForeignKey(i => i.CustomerId).OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity().HasOne(i => i.Distributor).WithMany()
.HasForeignKey(i => i.DistributorId).OnDelete(DeleteBehavior.SetNull);

#endregion

#region MagicLinkMetadata

modelBuilder.Entity().HasOne(ml => ml.GeneratedBy).WithMany()
.HasForeignKey(ml => ml.GeneratedById).OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity().HasOne(ml => ml.ModuleLicense).WithMany()
.HasForeignKey(ml => ml.ModuleLicenseId).OnDelete(DeleteBehavior.Cascade);

#endregion

#region ModuleLicense

modelBuilder.Entity().HasOne(ml => ml.Article).WithMany()
.HasForeignKey(ml => ml.ArticleId).OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity().HasOne(ml => ml.SystemLicense).WithMany(sl => sl.Licenses)
.HasForeignKey(ml => ml.SystemLicenseId).OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity().HasOne(ml => ml.UserIdentity).WithMany()
.HasForeignKey(ml => ml.UserIdentityId).OnDelete(DeleteBehavior.SetNull);

#endregion

#region SystemLicense

modelBuilder.Entity().HasOne(sl => sl.Customer).WithMany()
.HasForeignKey(sl => sl.CustomerId).HasConstraintName("CustomerId").OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity().HasOne(sl => sl.Distributor).WithMany()
.HasForeignKey(sl => sl.DistributorId).OnDelete(DeleteBehavior.SetNull);

modelBuilder.Entity().HasOne(sl => sl.SystemArticle).WithMany()
.HasForeignKey(sl => sl.ArticleId).HasConstraintName("ArticleId").OnDelete(DeleteBehavior.Restrict);

#endregion

#endregion
}
}
< /code>
Ich habe bereits versucht, die DataAttributes im Modell direkt ohne Wirkung festzulegen. Ich habe beide versucht, in der Konfiguration "HasconstraintName ()" hinzugefügt und zu entfernen, beide ohne Änderungen.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post