c# - How to use LINQ to assign while selecting to new object -


i have data contract called gameimage , gametone. trying join 2 entities, , assign unique random position between 0-11 image/tone association. able join tables unsure if there way assign position while creating object in linq lambda expression.

            // need random positions 0-11 to associated image/tone             var positions = enumerable.range(0, 11).shuffle().tolist();              // associate image/tones             imagetonedata = game.gameimages.shuffle()                 .join(game.gametones, gi => gi.gameid, gt => gt.gameid, (gi, gt) => new imagetonedata                 {                     image = new imagedata()                     {                         imagefilename = gi.image.imagefilename,                         imageid = gi.imageid                     },                     tone = new tonedata()                     {                         tonefilename = gt.tone.tonefilename,                         toneid = gt.toneid                     },                     position = // goes here?                 }); 

these data contracts

[datacontract] public class imagetonedata {     [datamember]     public imagedata image { get; set; }      [datamember]     public tonedata tone { get; set; }      [datamember]     public int position { get; set; } }  [datacontract] public class imagedata {     [datamember]     public int imageid { get; set; }      [datamember]     public string imagefilename { get; set; } } 

}

[datacontract] public class tonedata {     [datamember]     public int toneid { get; set; }      [datamember]     public string tonefilename { get; set; } } 

  var positions = enumerable.range(0, 11).orderby(a => guid.newguid()).tolist();    // associate image/tones             imagetonedata = game.gameimages.shuffle()                 .join(game.gametones, gi => gi.gameid, gt => gt.gameid, (gi, gt) => new imagetonedata                 {                     image = new imagedata()                     {                         imagefilename = gi.image.imagefilename,                         imageid = gi.imageid                     },                     tone = new tonedata()                     {                         tonefilename = gt.tone.tonefilename,                         toneid = gt.toneid                     },                     position = positions.first()                 }); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -