Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want Left join query using LInq to sql.
How can i convert below query into left joins query.

from customer_access in Adm.customer_accesses
join c in Adm.customers on customer_access.customer_no equals c.customer_no
join ur in Adm.user_roles on customer_access.user_id equals ur.user_id
join ar in Adm.app_roles on ur.role_id equals ar.role_id
select customer_access;

sql query is:
select * from customer_access ca left join customer c on ca.customer_no = c.customer_no left join user_roles ur on ca.user_id = ur.user_id left join app_roles ar on ur.role_id = ar.role_id

Thanks
Posted
Updated 12-Apr-12 20:00pm
v2

Here is a simple example of LINQ.
check this one; this might help you to understand the concept

XML
DataTable dt = new DataTable();

string sqlStatement1 = "select * from hsswith_view where cp_amount<='" + bug_amount + "' and no_of_days >='" + no_of_days + "'  or ep_amount<='" + bug_amount + "' and no_of_days >='" + no_of_days + "'";

SqlCommand sqlCmd1 = new SqlCommand(sqlStatement1,connection);
SqlDataAdapter sqlDa1 = new SqlDataAdapter(sqlCmd1);

          sqlDa1.Fill(dt1);
            var query = from r in dt1.AsEnumerable()
                        where r.Field<string>("pax") == no_person
                        select new
                        {
                            entry_id = r["entry_id"].ToString(),
                            pax = r["pax"].ToString(),
                            package = r["package"].ToString(),
                            no_of_days = r["no_of_days"].ToString(),
                            cp_amount = r["cp_amount"].ToString(),
                            ep_amount = r["ep_amount"].ToString()
                       };
            GridView1.DataSource = query;
            GridView1.DataBind();
 
Share this answer
 
There is no left join keyword in LINQ. You need to use DefaultIfEmpty().
This blog[^] might help you get to a solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900