Alex Rivera | Logout

Entity Framework 4.2 "The type is not attributed with EdmEntityTypeAttribute but is contained in an assembly attributed with EdmSchemaAttribute

Asked 2011-12-13T16:33:09.970
8

I am receiving the following error:

System.InvalidOperationException was unhandled Message=The type 'Judge' is not attributed with EdmEntityTypeAttribute but is contained in an assembly attributed with EdmSchemaAttribute. POCO entities that do not use EdmEntityTypeAttribute cannot be contained in the same assembly as non-POCO entities that use EdmEntityTypeAttribute.
Source=EntityFramework StackTrace: at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType) at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)....

 public class GenericRepository<TEntity> where TEntity : class
{
    internal z context;
    internal DbSet<TEntity> dbSet;

    public GenericRepository(z context)
    {
        this.context = context;
        this.dbSet = context.Set<TEntity>();
    }

    public GenericRepository()
    {
        this.context = new z();
        this.dbSet = context.Set<TEntity>();
    }

    public virtual IEnumerable<TEntity> Get(
        Expression<Func<TEntity, bool>> filter = null,
        Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
        string includeProperties = "")
    {

        IQueryable<TEntity> query = dbSet;

        if (filter != null)
        {
            query = query.Where(filter);
        }

        foreach (var includeProperty in includeProperties.Split
            (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
        {
            query = query.Include(includeProperty);
        }

        if (orderBy != null)
        {
            return orderBy(query).ToList();
        }
        else
        {
            return query.ToList(); //Getting error here!!
        }
    }

    public virtual TEntity GetByID(object id)
    {
        return dbSet.Find(id);
    }

    public vi
Edit
Report

1 Answer

15

Figured it out.

When I first started the program I was using an ObjectContext with the .edmx.

Then I read about EF 4.2 and decided to use DbContext.

The problem was my .edmx file was generating classes, as well as the DbContext T-4s.

The solution was to turn off code generation in the .edmx.

So now, only the DbContext T-4s are generating my POCO classes.

Hope this questions helps someone else in the future!

answered 2011-12-13T17:25:47.813

Your Answer