How to do joins in LINQ on multiple fields in single join

前端 未结 13 1933
小鲜肉
小鲜肉 2020-11-22 17:02

I need to do a LINQ2DataSet query that does a join on more than one field (as

var result = from x in entity
join y in entity2 
       on x.field1 = y.field1          


        
相关标签:
13条回答
  • 2020-11-22 18:07

    Declare a Class(Type) to hold the elements you want to join. In the below example declare JoinElement

     public class **JoinElement**
    {
        public int? Id { get; set; }
        public string Name { get; set; }
    
    }
    
    results = from course in courseQueryable.AsQueryable()
                      join agency in agencyQueryable.AsQueryable()
                       on new **JoinElement**() { Id = course.CourseAgencyId, Name = course.CourseDeveloper } 
                       equals new **JoinElement**() { Id = agency.CourseAgencyId, Name = "D" } into temp1
    
    0 讨论(0)
提交回复
热议问题