C
C#2y ago
Pandetthe

Problem with creating controller based on EF Core

Hi, I've got this error when I tried to create controller based on model
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace CafeApp.Models
{
public partial class CafeDbContext : DbContext
{
public CafeDbContext()
{
}

public CafeDbContext(DbContextOptions<CafeDbContext> options)
: base(options)
{
}

public virtual DbSet<CustomerInfo> CustomerInfos { get; set; } = null!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CustomerInfo>(entity =>
{
entity.ToTable("CustomerInfo");

entity.Property(e => e.Id)
.HasMaxLength(10)
.IsFixedLength();

entity.Property(e => e.Email)
.HasMaxLength(507)
.IsFixedLength();

entity.Property(e => e.Name)
.HasMaxLength(256)
.IsFixedLength();
});

OnModelCreatingPartial(modelBuilder);
}

partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace CafeApp.Models
{
public partial class CafeDbContext : DbContext
{
public CafeDbContext()
{
}

public CafeDbContext(DbContextOptions<CafeDbContext> options)
: base(options)
{
}

public virtual DbSet<CustomerInfo> CustomerInfos { get; set; } = null!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CustomerInfo>(entity =>
{
entity.ToTable("CustomerInfo");

entity.Property(e => e.Id)
.HasMaxLength(10)
.IsFixedLength();

entity.Property(e => e.Email)
.HasMaxLength(507)
.IsFixedLength();

entity.Property(e => e.Name)
.HasMaxLength(256)
.IsFixedLength();
});

OnModelCreatingPartial(modelBuilder);
}

partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}
No description
3 Replies
Tvde1
Tvde12y ago
Have you tried to clean & rebuild your solution?
ergazia
ergazia2y ago
Install (or update) NuGet package Microsoft.CodeAnalysis.CSharp.Workspaces version 2.0.0 or higher And then retry to scaffolding again
Pandetthe
Pandetthe2y ago
Thx that helped