Hi AliYilmaz,
You need to make use of GroupJoin with SelectMany in Lambda Expression.
Refer below example.
Database
I have made use of two tables namely VehicleTypes and VehicleSubTypes. The schema and the data present in both the tables are as follows.
VehicleTypes
VehicleSubTypes
You can download the database table SQL by clicking the download link below.
Download SQL File
HTML
<asp:GridView runat="server" ID="gvVehicles" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Type" HeaderText="Type" />
</Columns>
</asp:GridView>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
using (VehiclesDBEntities entities = new VehiclesDBEntities())
{
List<Vehicle> vehicles = entities.VehicleSubTypes
.GroupJoin(entities.VehicleTypes, vs => vs.VehicleTypeId, v => v.Id, (vs, v) => new { vs, v })
.SelectMany(vs => vs.v.DefaultIfEmpty(), (x, y) =>
new Vehicle
{
Id = x.vs.Id,
Name = x.vs.Name,
Type = y.Name
}).ToList();
gvVehicles.DataSource = vehicles;
gvVehicles.DataBind();
}
}
}
public class Vehicle
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
}
Screenshot