2
I am working with Entity Framework 6.1, using the approach code first. I mapped my class in the database through the class EntityTypeConfiguration
.
When mapping 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
In 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 you: i must use the Entity Framework standard to name the columns of my database table?
we need the
DAO.UF
and we need you to put all themapeamento
(Entitytypeconfiguration) in its entirety, because Hascolumnname recognizes this yes!!!– user6026
when I modify the field in the table to name, it works normally. The problem is that I own the classes in one pattern and the bank in another, it would be very difficult if I had to put my bank in the default of the Entity framework, just as the reverse would also be bad.
– dhielyton
I did not say different, what I want you to edit the question and put all the code matches your question, understood @dhielyton
– user6026
OK, I got it, I’ve done the editing. @Fccdias
– dhielyton
You could post the table schema in the database?
– Miguel Angelo