I'm working with the Entity Framework 6.1, using the code first approach. I mapped my class to the database through class EntityTypeConfiguration
.
When I map a property with a table field, using the code below, for example:
namespace Dominio
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class UF
{
private int iduf;
private string nome;
private string sigla;
public int IdUf
{
get { return this.iduf; }
set { this.iduf = value; }
}
public string Nome
{
get { return this.nome; }
set { this.nome = value; }
}
public string Sigla
{
get { return this.sigla; }
set { this.sigla = value; }
}
}
}
namespace DAO
{
class UFConfig:EntityTypeConfiguration<UF>
{
public UFConfig()
{
this.HasKey(u => u.IdUf);
this.Property(u =>u.IdUf).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(u => u.Sigla);
this.Property(u => u.Nome);
this.ToTable("uf");
this.Property(u => u.IdUf).HasColumnName("IDUF") ;
this.Property(u => u.Sigla).HasColumnName("SIGLA");
this.Property(u => u.Nome).HasColumnName("nome_UF");
}
}
}
Table in the Bank
CREATE TABLE [dbo].[uf](
[iduf] [int] NOT NULL,
[sigla] [varchar](2) NOT NULL,
[nome_uf] [varchar](20) NOT NULL,
CONSTRAINT [PK_uf] PRIMARY KEY CLUSTERED
(
[iduf] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
As a return, I have the following:
The data reader is incompatible with the specified 'DAO.UF'. A member of the type, 'Name', does not have a corresponding column in the data reader with the same name.
I ask: I have to use the default Entity Framework to name the columns of my database table?