I have two tables BIReport and tblFormat. I am using linq to sql in my project.
I want to get data using linq to sql which will be same as the following query.
Select A.*,B.* from Report A inner join tblFormat B on A.ReportId = B.SettingId.
Using above query it will get all data from both table. So How to receive all data from both tables using linq to sql.
Updated :
<form id="form1" runat="server">
<div>
<asp:GridView ID="grddata" runat="server"></asp:GridView>
</div>
</form>
Update2:
My query:
var QInnerJoin1 = (from p in objtest.Reports
join p2 in objtest.tblFormats
on p.ReportId equals p2.SettingID
where p2 != null
select new { p, p2 }).ToList();
grddata.DataSource = QInnerJoin1;
grddata.DataBind();
My Error and Data![enter image description here][2]
Solutions:
I have created a class for property which I need to bind to Grid view:
public class TestLinqToSql
{
public int ReportId { get; set; }
public string ReportName { get; set; }
public string FormatName { get; set; }
}
Then I have updated my linq to sql as per below:
List<TestLinqToSql> objList = (from p in objtest.Reports
join p2 in objtest.tblFormats
on p.ReportId equals p2.SettingID
where p2 != null
select new TestLinqToSql()
{
ReportId = p.ReportId,
ReportName = p.ReportName,
FormatName = p2.FormatName
}).ToList();
grddata.DataSource = objList1;
grddata.DataBind();
Its works for me. Thanks.