1
How do I get the name of the property DbQuery
using Generics?
I have the property:
public DbQuery<Pessoa> ConsultarPessoas { get; set; }
And in my repository:
DataContext.Query<T>().FromSql("ConsultarPessoas");
So far so good. Now I need to take the name of the property via Generics and set in place of ConsultarPessoas
.
It’s been a while since I’ve been researching.
?DataContext.Query<T>()
?DataContext.Query<T>().GetType()
?nameof(?DataContext.Query<T>())
And why do you need this? Almost every time I see this kind of need there’s an impression that you’re using something wrong and you don’t really need it, you can solve it in a better way.
– Maniero
@Maniero I usually take dbset in the constructor: dbset = Datacontext.Set<T>() and use it when requested: dbset. Find(id). Since I never bothered to know the name of the property. Now I intend to run a trial with fromSql() and I have to pass it in the parameter.
– Ronaldo Peixoto