I have a C# console application that takes a random bsn(sofi number) but now I have it that it shuffles the list and takes the first. But I want that it takes a random number from the list. Because of performance.
I have it like this:
var selectRandomBsnNumber = HelperManager.BrpPersoonReposHelper2.GetAll()
.OrderBy(x => Guid.NewGuid())
.Select(p => p.Bsn)
.First().Count();
I try it like this:
int takeRanomBsnNumber = 0;
var selectRandomBsnNumber = HelperManager.BrpPersoonReposHelper2.GetAll()
.OrderBy(x => Guid.NewGuid())
.Select(p => p.Bsn)
.Take(takeRanomBsnNumber)
.First().Count();
this is the method:
public virtual IQueryable<TEntity> GetAll()
{
return Repository.GetAll();
}
So this works:
var selectRandomBsnNumber = HelperManager.BrpPersoonReposHelper2.GetAll()
.OrderBy(x => Guid.NewGuid())
.Select(p => p.Bsn)
.First();
But is very slow
Comments
Post a Comment