0

I am using Linq to Sql to get two lists than take Union with another list. They are working fine. But I am wondering if it can be done in one Query or two instead of three that I have.

Querys are

var l = (from t in T_list1
         where t.Date == DateTime.Today 
         select new 
         {   
             oldDate=t.OldDate,
             Name=t.name,
             Email=t.EmailAddress,
             list2TableId=t.l2Id,
             CustomerId=t.customerId
         });


var l2=(from d in T_list2
        from e in l1
        where d.Id == e.list2TableId
        select new
        {                
            Date=d.oldDate,
            CName=d.Name,
            Experience=e.experience,            
        });

list2.Dump();
var l3 = list2.Union(list3).ToList();

I was looking at this post but didnt work. Combining 2 Linq queries into 1 Thanks for your input.

2
  • What is the problem with your code and why do you want to change it? Commented Jun 13, 2013 at 1:44
  • I suspect some typos but the posted code makes little sense. Please check l/l1/list1 and l2/list2 Commented Jun 16, 2013 at 7:31

1 Answer 1

0

You could do a join instead of the 2 queries:

         var l = (from t in T_list1
                  join d in T_list2 on t.l2Id equals d.Id
                 where t.Date == DateTime.Today 
                 select new 
                 {
                 oldDate=t.OldDate,
                 Name=t.name,
                 Email=t.EmailAddress,
                 list2TableId=t.l2Id,
                 CustomerId=t.customerId
                 Date=d.oldDate,
                 CName=d.Name
                 Experience=e.experience,
                 });

I haven't tested the query but it should show you the rough idea.

Have a look at JOINs in SQL & Linq to get more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.