sql server - How to convert SQL Left Join query to Linq to Entity in C#? -


i have table: material(id,name,materialparentid)

select  c1.id,c1.name parentname,c2.id,c2.name    material c1 left join material c2 on      c1.id = c2.materialparentid  id  parentname  id  name 1   aluminium   2   cavity 1   aluminium   3   copper 1   aluminium   4   flooring 2   cavity     null null 3   copper     null null 4   flooring   null null 5   glass      null null 

i want convert above sql query linq query using liq entities.

help appreciated!

if table reading create view , when using reverse engineering make sure have views imported.

or if did want done in linq here msdn example

var innerjoinquery =     cust in customers     join dist in distributors on cust.city equals dist.city     select new { customername = cust.name, distributorname = dist.name }; 

this how yours look

var material = m in db.materials                        join m2 in db.materials on m.id equals m2.materialparentid                        select new {parentid = m.id, parentname = m.name, m2.id, m2.name }; 

i have edited post above can see have included parentid make columns unique


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -