Jump to content

Recommended Posts

Posted

i have a list of id's that are passed to a service.

 

List<long> individualIDs = new List<long> { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21...........}; //This list is pulled from DB

 

clinet.invoke(individualIDs);

 

currently the count of the individualIDs is more than 1000

 

ippudu oka loop laga chesi 100 records at a time pampinchali 

konchem help karo yaaro 

Posted

I'm trying to do this way. is there any better way ??

 

List<long> individualIDs = new List<long> { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21...........}; //This list is pulled from DB

int batchsize = 3;
for (int i = 0; i < individualIDs.Count; i = 1 + batchsize)
                {
                  clinet.invoke(IndividualIds.Skip(i).Take(batchSize).ToList());
                }
Posted

public static List<List<long>> Split(List<long> source)
{
            return source.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index / 100).Select(x => x.Select(v => v.Value).ToList()).ToList();
}

 

 

This func will split the list of 1000 longs to 10 lists of 100 longs.

 

 

Posted

public static List<List<long>> Split(List<long> source)
{
            return source.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index / 100).Select(x => x.Select(v => v.Value).ToList()).ToList();
}

 

 

This func will split the list of 1000 longs to 10 lists of 100 longs.

but always morethen 1000 records vasthyaaaa

Posted

but always morethen 1000 records vasthyaaaa

 

enni vachina list of 100 long ga divide chesthundi kada bhayya. If less than hundred ayithey okate list of list return chesthundi

 

for ex:

 

1005 records vachayi anuko db ninchi

 

10 lists of 100 each and 1 list of 5  so total 11 lists return chesthundi func

 

15 records ee vachayi anuko db ninchi

 

only one list of 15 ee return chesthundi func.

Posted

 

I'm trying to do this way. is there any better way ??

 

List<long> individualIDs = new List<long> { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21...........}; //This list is pulled from DB

int batchsize = 3;
for (int i = 0; i < individualIDs.Count; i = 1 + batchsize)
                {
                  clinet.invoke(IndividualIds.Skip(i).Take(batchSize).ToList());
                }

 

 

 

 

List<List<long>> splitlist = Split(individualIDs);

 foreach (var lst in splitlist)
 {
    client.invoke(lst);           
 }

public static List<List<long>> Split(List<long> source)
{
  return source.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index / 100).Select(x => x.Select(v => v.Value).ToList()).ToList();
}

Posted

List<List<long>> splitlist = Split(individualIDs);

 foreach (var lst in splitlist)
 {
    client.invoke(lst);           
 }

public static List<List<long>> Split(List<long> source)
{
  return source.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index / 100).Select(x => x.Select(v => v.Value).ToList()).ToList();
}

bhayya ee code lo for each lo ki vellaka the service is called for every single record kada ?

 

for each taruvata yemi avutundo ardam kaaledu :(

Posted

bhayya ee code lo for each lo ki vellaka the service is called for every single record kada ?

 

for each taruvata yemi avutundo ardam kaaledu :(

 

Every single record ki service call avvadhu bhayya.

 

List<List<long>> splitlist = Split(individualIDs); ee line of code use chesi aa 100 long list ni10 lists each containing 100 longs ki split chesthunnam like below

 

so {1,2,3 4,,,,,1000} list ni {{1,2,,,100},{101,102,,,,,,200},{201,202,,,,300},,,,,{901,902,1000}} ila split cheskuntunnam..

 

split cheskunna danni foreach loki pamputhannam so foreach 100 item list ki oka sari client.invoke call avuthundi..

 

so 1000 longs ki total ga 10 times client.invoke call avuthundi..

Posted

i have a list of id's that are passed to a service.

 

List<long> individualIDs = new List<long> { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21...........}; //This list is pulled from DB

 

clinet.invoke(individualIDs);

 

currently the count of the individualIDs is more than 1000

 

ippudu oka loop laga chesi 100 records at a time pampinchali 

konchem help karo yaaro 

 

 

bhayya simple ga  ok counter pettukoni skip take cheyochuga

int counter = 0;
while(true){
var sublist = individualIDs.Skip(counter).Take(100);   //ante first 100 elements vasthayi
if (!sublist.Any()) break ;
clinet.invoke(sublist.ToList<Long>()); //call webservice
counter += 100; //increase counter
}

I hope it works.. and simple ga artham avuthundi anukuntunna

Posted

bhayya simple ga  ok counter pettukoni skip take cheyochuga

int counter = 0;
while(true){
var sublist = individualIDs.Skip(counter).Take(100);   //ante first 100 elements vasthayi
if (sublist == null) break ;
clinet.invoke(sublist.ToList<Long>()); //call webservice
counter += 100; //increase counter
}

I hope it works.. and simple ga artham avuthundi anukuntunna

 

if (sublist == null)

 

ee statement true avvadhu bhayya code lo.

This will be an infinite loop.

enumerable zero results yield chesthundi kani null avvadhu ee case lo
 

Posted

if (sublist == null)

 

ee statement true avvadhu bhayya code lo.

This will be an infinite loop.

enumerable zero results yield chesthundi kani null avvadhu ee case lo
 

yeah correct e.

 

if(sublist.Any())  tho replace karna hai

Posted

yeah correct e.

 

if(sublist.Any())  tho replace karna hai

 

if(! sublist.Any()) tho

 

:)

 

 

agreed simple and good solution.

Posted

if(! sublist.Any()) tho

 

:)

 

 

agreed simple and good solution.

 

lol.. thats why we send code reviews to team .

×
×
  • Create New...