What is the return type of my linq query?

前端 未结 4 926
野的像风
野的像风 2020-12-29 10:41

I have two tables A & B. I can fire Linq queries & get required data for individual tables. As i know what each of the tables will return as shown in example. But,

4条回答
  •  时光说笑
    2020-12-29 11:04

    As you have created an anonymous(Anonymous types are generated by the compiler, so we cannot know the type name in our codes) class so that you can not return it.Create a separate class with three properties Id,Name and Address then returned it.

      public class Contact
            {
                public int Id { get; set; }
                public string Name { get; set; }
                public string Address { get; set; }
    
            }
    
     private IList GetJoinAAndB()
        {
            var query = from a in objA
                        join b in objB
                        on a.ID equals b.AID
                        select new Contact{ a.ID, a.Name, b.Address };
            return query.ToList();
        }
    

提交回复
热议问题