Hi Juan,
The selection of the keyselector depends on your requirement. The
outerkeyselector and the innerkeyselector are used to be compared
internally. If the outerkeyselector of the outer item equals to the
innerkeyselector of the inner item current linked item will be added to the
result collection.
You can try following code in ASP.NET Web Project to test:
Aspx.cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<Employee> list1 = new List<Employee>();
List<Employee> list2 = new List<Employee>();
Employee x0 = new Employee() { ID = 1, ID2=1, Name = "Name"
};
Employee x1 = new Employee() { ID = 1, ID2 = 2, Name =
"Name2" };
list1.Add(x0);
list1.Add(x1);
Employee x2 = new Employee() { ID = 1, ID2 = 1, Name =
"Name3" };
Employee x3 = new Employee() { ID = 1, ID2 = 2, Name =
"Name4" };
Employee x4 = new Employee() { ID = 1, ID2 = 2, Name =
"Name5" };
list2.Add(x2);
list2.Add(x3);
list2.Add(x4);
this.GridViewl1.DataSource = list1;
this.GridViewl1.DataBind();
this.GridViewl2.DataSource = list2;
this.GridViewl2.DataBind();
var q = list1.Join(list2, x => MyOuterKeySelector(x.ID, x.ID2),
o => MyInnerKeySelector(o.ID, o.ID2), (x, o) => new { list1_id = x.ID,
list1_id2 = x.ID2, list2_id = o.ID, list2_id2 = o.ID2, list1_name = x.Name,
list2_name = o.Name });
this.GridViewResult.DataSource = q;
this.GridViewResult.DataBind();
}
object MyOuterKeySelector(object o, object o2)
{
//decide the key selector based on your requirement.
//in this case I can convert it to string and insert a custom
separator
return o + "_" + o2;
}
object MyInnerKeySelector(object o, object o2)
{
//decide the key selector based on your requirement.
//in this case I can convert it to string and insert a custom
separator
return o + "_" + o2;
}
}
public class Employee {
public int ID { get; set; }
public int ID2 { get; set; }
public string Name { get; set; }
}
Aspx:
list1<br />
<asp:GridView ID="GridViewl1" runat="server">
</asp:GridView>
list2<br />
<asp:GridView ID="GridViewl2" runat="server">
</asp:GridView>
Join<br />
<asp:GridView ID="GridViewResult" runat="server">
</asp:GridView>
You can see it's free for you to choose the keyselector.
Please let me know if you have further questions.
Regards,
Allen Chen
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.