no implicit reference conversion to System.Data.Entity.DbContext

I am getting the following compile error in my project:
The type 'GenericRepoWebApp.Data.DataAccess.SqlServer.FooBarEntities1'
cannot be used as type parameter 'C' in the generic type or method
'GenericRepoWebApp.Data.DataAccess.Infrastructure.GenericRepository<C,T>'.
There is no implicit reference conversion from 'GenericRepoWebApp.Data.DataAccess.SqlServer.FooBarEntities1'
to 'System.Data.Entity.DbContext'.      
C:\Code\Temp\GenericRepoWebAppVs2010\GenericRepoWebApp.Data\DataAccess\SqlServer\FooRepository.cs       line 9
Thanks in advance for any help given.
For clarity I have put my code below:
GenericRepoWebApp.Data=>DataAccess=>SqlServer=>FooRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericRepoWebApp.Data.DataAccess.Infrastructure;
//using System.Data.Entity.DbContext;
using System.Data.Entity;
namespace GenericRepoWebApp.Data.DataAccess.SqlServer {   
    public class FooRepository :
        GenericRepository<FooBarEntities1, Foo>, IFooRepository 
        {
        public Foo GetSingle(int fooId) 
        {
            var query = GetAll().FirstOrDefault(x => x.FooId == fooId);
            return query;
        }
    } 
}

Open in new window

GenericRepoWebApp.Data=>DataAccess=>Infrastructure=>GenericRepository.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
namespace GenericRepoWebApp.Data.DataAccess.Infrastructure {
    public abstract class GenericRepository<C, T> :
        IGenericRepository<T> where T : class where C : DbContext, new() {
        private C _entities = new C();
        protected C Context {
            get { return _entities; }
            set { _entities = value; }
        }
        public virtual IQueryable<T> GetAll() {
            IQueryable<T> query = _entities.Set<T>();
            return query;
        }
        public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate) {
            IQueryable<T> query = _entities.Set<T>().Where(predicate);
            return query;
        }
        public virtual void Add(T entity) {
            _entities.Set<T>().Add(entity);
        }
        public virtual void Delete(T entity) {
            _entities.Set<T>().Remove(entity);
        }
        public virtual void Edit(T entity) {
            _entities.Entry(entity).State = (EntityState) System.Data.EntityState.Modified;
        }
        public virtual void Save() {
            _entities.SaveChanges();
        }
        private bool disposed = false;
        protected virtual void Dispose(bool disposing) {
            if (!this.disposed)
                if (disposing)
                    _entities.Dispose();
            this.disposed = true;
        }
        public void Dispose() {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}

Open in new window

homeshopperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

louisfrCommented:
What is the definition of FooBarEntities1?
homeshopperAuthor Commented:
Thank you for your comment. Thanks in advance for any help given.
Below I have put the rest of the code.
ConnectionString in Web.Config
<add name="FooBarEntities1" connectionString="metadata=res://*/DataAccess.SqlServer.FooBarModel.csdl|res://*/DataAccess.SqlServer.FooBarModel.ssdl|res://*/DataAccess.SqlServer.FooBarModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\;initial catalog=FooBar;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Open in new window

FooBarModel.edmx    Foo.cs & Bar.cs
using System;
using System.Collections.Generic;
namespace GenericRepoWebApp.Data.DataAccess.SqlServer
{
    public partial class Foo
    {
        public int FooId { get; set; }
        public string FooName { get; set; }
    }  
}
using System;
using System.Collections.Generic;
namespace GenericRepoWebApp.Data.DataAccess.SqlServer
{
    public partial class Bar
    {
        public int BarId { get; set; }
        public string BarName { get; set; }
    }
}

Open in new window

IFooRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericRepoWebApp.Data.DataAccess.SqlServer;
namespace GenericRepoWebApp.Data.DataAccess.Infrastructure {
    public interface IFooRepository : IGenericRepository<Foo> {
        Foo GetSingle(int fooId);
    }
}

Open in new window

IGenericRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace GenericRepoWebApp.Data.DataAccess.Infrastructure {
    public interface IGenericRepository<T> : IDisposable where T : class {
        IQueryable<T> GetAll();
        IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
        void Add(T entity);
        void Delete(T entity);
        void Edit(T entity);
        void Save();
    }
}

Open in new window

App.Config
<add name="FooBarEntities1" connectionString="metadata=res://*/DataAccess.SqlServer.FooBarModel.csdl|res://*/DataAccess.SqlServer.FooBarModel.ssdl|res://*/DataAccess.SqlServer.FooBarModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\;initial catalog=FooBar;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Open in new window

louisfrCommented:
I don't see any class named FooBarEntities1, only a connection string. Do you have a class inheriting from DbContext?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

homeshopperAuthor Commented:
Thank you for your comment. It made me realize that a complete file was missing.
I have now added a file FooBarModel.Content.cs, code listed below:
I have deleted files Foo.cs and Bar.cs previously listed.
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace GenericRepoWebApp.Data.DataAccess.SqlServer
{
    public partial class FooBarEntities1 : DbContext
    {
        public FooBarEntities1()
            : base("name=FooBarEntities1")
        {
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
        public DbSet<Bar> Bars { get; set; }
        public DbSet<Foo> Foos { get; set; }
    }
}

Open in new window

The project now compiles, but am now getting a different error elsewhere in the project.
In the web.Config file of GenericRepoWebApp I have the following listed below:
in GenericRepoWebApp.Data it references EntityFramework version 6.0.0.0,
runtime version 4.0.30319.
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

Open in new window

The new error is listed below:
Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Open in new window

louisfrCommented:
Add a reference to System.Data.Entity.dll in your project.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
homeshopperAuthor Commented:
Thank you for your reply. I have been trying to narrow down the problem.
so far, in both projects GenericRepoWebApp & GenericRepoWebApp.Data
there is a reference to EntityFramework Version 6.0.0.0 & System.Data.Entity version 4.0.0.0
however, in the Index.cshtml is the following:
@model IEnumerable<GenericRepoWebApp.Data.DataAccess.SqlServer.Foo>
When hovering over the above a message is displayed as follows:
Module 'System.Data.Entity, version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
should be referenced.
Thanks in advance for the help.
homeshopperAuthor Commented:
Finally, found the source of the problem.
in web.config I have added the following:
 <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.