I use entity framework and Im trying to make such a query generic, so it can be used for any entity type (with an assumption that each entity has property int Id
).
I tried something like this, but there is no collection ctx.TEntity or something similiar:
public class Queries<TEntity> where TEntity : AbstractEntity
{
public Func<AdventureWorksEntities, int, TEntity> getQuery() {
return
CompiledQuery.Compile<AdventureWorksEntities, int, Entity>(
(ctx, num) => ctx.TEntity.First(x => x.Id>num));
}
}
AbstractEnitity:
public abstract class AbstractEntity {
[Key]
public int Id {get; set};
}
Thanks for your ideas :)