Lucas Rodrigues Sena
Lucas Rodrigues Sena

Reputation: 399

Working with generic model Problems with missing references on visual studio 2012 entity framework

EntityFramework runtime v4.0.30319 version 5.0.0.0

public abstract class AbstractPessoaFisicaDao<T>:IBasePessoaFisicaDao<T> where T: class
{

    SupremaDesEntities entidades = new SupremaDesEntities();
    Cadastro_PessoaFisica Pessoa = new Cadastro_PessoaFisica();

    public void Add(T pEntity)
    {
        entidades.Cadastro_PessoaFisica.AddObject();
    }

Error 1 'System.Data.Entity.DbSet' does not contain a definition for 'AddObject' and no extension method 'AddObject' accepting a first argument of type 'System.Data.Entity.DbSet' could be found (are you missing a using directive or an assembly reference?) c:\users\msbow\documents\visual studio 2012\Projects\Inside.Net.EF\Inside.Net.EF.Data\AbstractPessoaFisicaDao.cs 26 45 Inside.Net.EF.Data

I was studying this in visual studio 2010, I now have the ultimate version 2012 and can not adjust this reference, already downloaded the framework and several dlls nothing.

Upvotes: 0

Views: 959

Answers (1)

Scottie
Scottie

Reputation: 11308

Try:

SupremaDesEntities entidades = new SupremaDesEntities(); 

public void Add(T pEntity) 
{         
    entidades.Set<T>().Add(pEntity);
} 

Or, if you want to keep the entity type strongly typed:

SupremaDesEntities entidades = new SupremaDesEntities(); 

public void Add(Cadastro_PessoaFisica pessoa) 
{ 
    entidades.Cadastro_PessoaFisica.Add(pessoa); 
} 

Upvotes: 1

Related Questions