problem wth migration blazor wasm

sblb 1,141 Reputation points

Hi, I have two class that created the Foregin Key.

One think I don't understand when i've make the migration a new column is created ProjetModelIdProjet then I didn't define this column.

When I invoke put method eg the column ProjetModelIdProjet is filled and the IdProjet = 0

If the IdProjet is not filled there will be problems with different methods.

How I can fix this problem?

I tried to delete the [key] attribute but the migrations doesn't work in this case.

thanks in advance to your help!

 public class ProjetModel 
        public int IdProjet { get; set; }
        public DateTime DateProjet { get; set; }
        public string? Title { get; set; }        
        public string? Type { get; set; }
        public string? Level { get; set; }
        public bool? IsCompleted { get; set; }
        public string? Statut { get; set; }
        public int ProjetCount { get; set; }
        public string? ProjetCountId {
                return $"{ProjetCount.ToString().PadLeft(3, '0')}";
            set { }

        public byte[]? ConcurrencyToken { get; set; }

        public List<ActionItemProjet>? ActionItemProjets { get; set; }

    public class ActionItemProjet
        public int ActionId { get; set; }
        public string? Tilte { get; set; }
        public string? DescriptionA { get; set; }
        public string? State { get; set; }
        public DateTime? OpenDate { get; set; }
        public DateTime? PlanDate { get; set; }
        public DateTime? CloseDate { get; set; }
        public int IdProjet { get; set; }
        public ProjetModel? ProjetModel { get; set; }

In applicationDbContext

   protected override void OnModelCreating(ModelBuilder modelBuilder)
                .HasOne(p => p.ProjetModel)
                .WithMany(b => b.ActionItemProjets);


below the results of the migrations

                name: "ActionItemProjets",
                columns: table => new
                    ActionId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Tilte = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    DescriptionA = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    State = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    OpenDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    PlanDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CloseDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IdProjet = table.Column<int>(type: "int", nullable: false),
                    ProjetModelIdProjet = table.Column<int>(type: "int", nullable: true)
                constraints: table =>
                    table.PrimaryKey("PK_ActionItemProjets", x => x.ActionId);
                        name: "FK_ActionItemProjets_ProjetModels_ProjetModelIdProjet",
                        column: x => x.ProjetModelIdProjet,
                        principalTable: "ProjetModels",
                        principalColumn: "IdProjet");

A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,109 questions
{count} votes