I'm following this tutorial . When creating the class below gave an error:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain.entities;
using System.Data.Entity.ModelConfiguration;
namespace DataAccess.Map
{
public class CursoMap : EntityTypeConfiguration<Curso>
{
public CursoMap()
{
/*O método ToTable define qual o nome que será
dado a tabela no banco de dados*/
ToTable("Curso");
//Definimos a propriedade CursoId como chave primária
HasKey(x => x.CursoId);
//Descricao terá no máximo 150 caracteres e será um campo "NOT NULL"
Property(x => x.Descricao).HasMaxLength(150).IsRequired();
HasMany(x => x.ProfessorLista)
.WithMany(x => x.CursoLista)
.Map(m =>
{
m.MapLeftKey("CursoId");
m.MapRightKey("ProfessorId");
m.ToTable("CursoProfessor");
});
}
}
}
The error occurred in the following parts: HasKey(x => x.CursoId);
Property(x => x.Descricao)
HasMany(x => x.ProfessorLista)
Error Message:
Error 1 The type arguments for method
'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration.HasK
ey (System.Linq.Expressions.Expression>) '
can not be inferred from the usage. Try specifying the type arguments
explicitly.
Class Course:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Domain.entities
{
class Curso
{
public Curso()
{
ProfessorLista = new List<Professor>();
Ativo = true;
}
public int CursoId { get; set; }
public string Numero { get; set; }
public string Descricao { get; set; }
public bool Ativo { get; set; }
public virtual ICollection<Professor> ProfessorLista { get; set; }
public override string ToString()
{
return Descricao;
}
}
}
What do I need to do?