Olá, Daniel. Tudo bem e vc?
Seguem as classes:
using System.ComponentModel.DataAnnotations;
namespace FilmesAPI.Models
{
public class Filme
{
[Key]
[Required]
public int Id { get; set; }
[Required(ErrorMessage = "O campo {0} é obrigatório.")]
public string Titulo { get; set; }
[Required(ErrorMessage = "O campo {0} é obrigatório.")]
public string Diretor { get; set; }
[Required(ErrorMessage = "O campo {0} é obrigatório.")]
public string Genero { get; set; }
[Range(1, 600, ErrorMessage = "A {0} deve ter no mínimo {1} e no máximo {2} minutos.")]
public int Duracao { get; set; }
}
}
using FilmesAPI.Models;
using Microsoft.EntityFrameworkCore;
namespace FilmesAPI.Data
{
public class FilmeContext : DbContext
{
public FilmeContext(DbContextOptions<FilmeContext> options) : base(options) { }
public DbSet<Filme> Filmes { get; set; }
}
}
Dependências:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.5.21301.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-preview.5.21301.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-preview.4.21253.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
</Project>