c# - join two list in linq initializing properties one time -
i have found many examples join list in linq exact problem not solved.
i have join list list , list
i have initialized properties of list , when joining have again initialize properties of , added properties b.
list<a> listb = c in country                 select new                 {                   countryid=c.countryid                    countryname=c.countryname                   } ; list<a> lista = d in data                 select new                 {                   name = d.name                   age= d.age,                   city=d.city,                   countryid=d.countryid                    } ; now initialize country property in list joining both list here problem starts
  lista = d in lista             join c in listb on d.countryid=c.countryid                     select new                     {                       name = d.name                       age= d.age,                       city=d.city,                          country=c.countryname                     } ; see in above join have again initialize name, age , city can initialize properties @ 1 place.
do not use lista , listb - join countries , data directly:
from c in country join d in data    on c.countryid equals d.countryid  select new {       name = d.name       age = d.age,       city = d.city,       country = c.countryname }; btw why use a class lista , listb if both contain different data? should two different classes.
Comments
Post a Comment