Getting Error : Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member acce

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
I try to left join two list and update first list's one property value with the value from second list's property but getting error Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

This code is not giving any error

var list1 = new List<ItemOne>
{
new ItemOne {IDItem = 1, OneProperty = "1"},
new ItemOne {IDItem = 2, OneProperty = null},
new ItemOne {IDItem = 3, OneProperty = "3"},
new ItemOne {IDItem = 4, OneProperty = "4"}
};
var list2 = new List<ItemTwo>
{
new ItemTwo {IDItem = 2, TwoProperty = "2"},
new ItemTwo {IDItem = 3, TwoProperty = "3"},
};


var query = list1.Join(list2, l1 => l1.IDItem, l2 => l2.IDItem, (l1, l2) =>
{
l1.OneProperty = l2.TwoProperty;
return l1;
});

But this below code is throwing error.......what i am missing ?

var data = (from a in list1
join b in list2
on a.IDItem equals b.IDItem into c
from d in c.DefaultIfEmpty()
select new
{
a.OneProperty=(d==null ? string.Empty : d.TwoProperty)
}).ToList();



class ItemOne
{
public int IDItem { get; set; }
public string OneProperty { get; set; }
}

class ItemTwo
{
public int IDItem { get; set; }
public string TwoProperty { get; set; }

}


please guide me and rectify my code. thanks

Continue reading...
 
Back
Top