Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
C# Pase la propiedad de la entidad a una función para usar en LINQ

Imagina que tengo una clase como esta:

 public class BaseRepo<T> where T : class { private readonly DbSet<T> table; public BaseRepo(MyDbContext context) { this.table = context.Set<T>(); } }

Quiero implementar la siguiente lógica en esta clase.

 string GenerateUniqueStringFor(PropertyName) { string val = string.Empty; do { val = GenerateRandomString(); } while (this.table.FirstOrDefault(x => x.PropertyName == val) is not null); return val; }

El problema es que no sé cómo pasar Property/PropertyName. La forma ideal de llamarlo sería:

 string val = _myRepo.GenerateUniqueStringFor(x => x.PropertyName);
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si entiendo correctamente, puede intentar pasar un delegado Func

 string GenerateUniqueStringFor(Func<T,string> func) { string val = string.Empty; do { val = GenerateRandomString(); } while (this.table.FirstOrDefault(x => func(x) == val) is not null); return val; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!