What is the syntax for an inner join in LINQ to SQL?

后端 未结 19 2069
感情败类
感情败类 2020-11-22 04:25

I\'m writing a LINQ to SQL statement, and I\'m after the standard syntax for a normal inner join with an ON clause in C#.

How do you represent the follo

19条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 04:59

    basically LINQ join operator provides no benefit for SQL. I.e. the following query

    var r = from dealer in db.Dealers
       from contact in db.DealerContact
       where dealer.DealerID == contact.DealerID
       select dealerContact;
    

    will result in INNER JOIN in SQL

    join is useful for IEnumerable<> because it is more efficient:

    from contact in db.DealerContact  
    

    clause would be re-executed for every dealer But for IQueryable<> it is not the case. Also join is less flexible.

提交回复
热议问题