0
I’m following this tutorial. 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>)'
cannot 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 I need to do?
Set the course class
– novic
I’ve set the course.
– HeyJoe
At what point does the error occur? Another point is missing some fields or why?
– novic
Look, I’m just following the tutorial, I don’t understand this syntax. The error appeared when I created this class. What exactly is missing? That must be why you’re making a mistake.
– HeyJoe
Well, I’ll continue with the tutorial and see what happens.
– HeyJoe
Well the course class should be
public class Curso
lacked putpublic
, another point these classes all have relationship, if there is some class missing or something can cause errors, first of all follow the whole tutorial ...– novic
That was right, missed the public in Course class. How would the answer to this post?
– HeyJoe