sharparchitecture/Sharp-Architecture — Issue #37: LinqRepository cannot be cast to ILinqRepository
Author: seif
Created: 2012-02-07 17:38:36+00:00
State: open

Actually, to make sure I have everything setup correctly in my project for the 2.0.1 version, I created a new project. Point to a database with one table and one (string) field. I then did a query in the HomeController using LinqRepo so I have this:

public HomeController(ILinqRepository mealRepo)
{
this.mealRepo = mealRepo;
}

public ActionResult Index()
{
var meals = mealRepo.FindAll();
return View();
}

In the ComponentRegistrar I registered the LinqRepo inside AddGenericRepositoriesTo method and so I have this:

container.Register(
Component.For(typeof(ILinqRepository<>))
.ImplementedBy(typeof(LinqRepository<>))
.Named("linqRepository"));

That used to work in 2.0RC. So I thought maybe I should also register ILinqRepositoryWithTypedId to follow what was done for "INHibernateRepository" and so I have this in the code:

container.Register(
Component.For(typeof(ILinqRepository<>))
.ImplementedBy(typeof(LinqRepository<>))
.Named("linqRepository"));

container.Register(
Component.For(typeof(ILinqRepositoryWithTypedId<,>))
.ImplementedBy(typeof(LinqRepositoryWithTypedId<,>))
.Named("linqRepositoryWithTypedId"));

But I still got the same error:
Object of type 'SharpArch.NHibernate.LinqRepository`1[SA_Test.Domain.Person]' cannot be converted to type 'SharpArch.Domain.PersistenceSupport.ILinqRepository`1[SA_Test.Domain.Person]'.