1 - ADO - (Class Library Project)
2 - .edmx file
3 - An Interface
using System;
using System.Linq;
using System.Linq.Expressions;
namespace LojaVirtual.DAO.Interfaces
{
public interface IBaseCRUD<T>
{
void Adicionar(T pEntity);
void Deletar(T pEntity);
void Attach(T pEntity);
void Detach(T pEntity);
void Update(T pEntity);
IQueryable<T> Selecionar(Expression<Func<T,bool>> where );
IQueryable<T> SelecionarTodos();
void Salvar();
}
}
4 - An AbstratCrud:
using System;
using System.Linq;
using System.Linq.Expressions;
using LojaVirtual.DAO.Interfaces;
namespace LojaVirtual.DAO
{
public abstract class AbstractCRUD<T> :IBaseCRUD<T> where T:class
{
LOJAEntities loja = new LOJAEntities();
public void Adicionar(T pEntity)
{
loja.AddObject(pEntity.GetType().Name, pEntity);
}
public void Deletar(T pEntity)
{
loja.DeleteObject(pEntity);
}
public void Attach(T pEntity)
{
loja.AttachTo(pEntity.GetType().Name, pEntity);
}
public void Detach(T pEntity)
{
loja.Detach(pEntity);
}
public void Update(T pEntity)
{
loja.ApplyCurrentValues<T>(pEntity.GetType().Name, pEntity);
}
public IQueryable<T> Selecionar(Expression<Func<T, bool>> where)
{
return loja.CreateObjectSet<T>().Where(where);
}
public IQueryable<T> SelecionarTodos()
{
return loja.CreateObjectSet<T>();
}
public void Salvar()
{
loja.SaveChanges();
}
}
}
In the version of ".Net Framework 4.5" I have the same structure, but, my AbstractCRUD can not access the IBaseCRUD information
Error:
Error CS1061 'CRUD_MVCEntities' does not contain a definition for 'AddObject' and no extension method 'AddObject' accepting a first argument of type 'CRUD_MVCEntities' could be found using directive or an assembly DAL C: \ Users \ name \ Downloads \ Project.FileInput \ DAL \ AbstractCRUD.cs 15 Active
Does anyone know why? Thank you