1
I’m using the following tutorial to use the Repository Pattern:
Follows my repository class
public class Repository<T> : IDisposable, IRepository<T> where T : class
{
protected readonly EntityContext ctx;
public Repository(EntityContext _ctx)
{
this.ctx = _ctx;
}
public T getByID(object id)
{
return ctx.Set<T>().Find(id);
}
}
But at the time of the creation of the method GetByID(int id)
, is popping the error below.
Dbset does not contain a Definition for 'Find' and no Extension method 'Find' Accepting a first argument of type '
DbSet<T>
' could be found (are you Missing a Directive or an Assembly Reference?)
In the tutorial I’m following, the instructor teaches the same way I showed here.
Are you using
using System.Collections.Generic
?– LP. Gonçalves
Yeah, I am. Yeah;
using System.Collections.Generic;
– Renan Narciso
using System.Linq
– Leandro Angelo
What version of . NET? What version of the Entity Framework?
– bunomonteiro
Try swapping Entitycontext for Dbcontext
– bunomonteiro
Is that Entityframework Core? Where did this Entitycontext class come from?
– Jéf Bueno
@bunomonteiro the version of . NET is .NET Framework 4.7.1 and the version of the Entity Framework I used at the time of installation via Nuget was as follows: -Version 7.0.0-rc1-final -Pre
– Renan Narciso
@LINQ It’s not Core... And the entitycontext class is the context of apication, where I have declared the classes that will be reflected as a database.
– Renan Narciso
@Renannarciso Please add the relevant snippets to your question and not to external sources. My network is blocked here.
– Jéf Bueno
@bunomonteiro, I switched Entitycontext for Dbcontext and still I can’t call the Find method()
– Renan Narciso
Dude, I think it’s because the find needs a lambda expression, so it would have to be like
Find(x => x.valor == id)
– Gustavo Forte Andreli
Installs -Version 6.2.0 which is stable.
– bunomonteiro
@Gustavoforteandreli I know I need a lambda expression. The problem is I’m not able to use it
– Renan Narciso
Have you tried changing the method
public T getByID<T>(object id)
?– novic
Hello @Virgilionovic the problem has already been solved
– Renan Narciso
You can put the solution.
– novic
Yes, thanks for the info. Solution.
– Renan Narciso