Of course they are pretty similar (comprehension query) but not same (lambda query is only similar in logic). If you use LINQ as exact same way as SQL, no doubt it causes you headache.
1. outer join: In LINQ, the group join has similar function as outer join in SQL but not so powerful.
2. group by function: More convenient (easily getting key value) but only group by one key rather than by several fields as that in SQL. If you really need group by multi-fields, you can concatenate multi-fields as a group key. And LINQ’s groupby result is individual group objects rather than individual records as SQL.
3. Sub-query: Since most LINQ operators are lazy operators (execute until output result or run a greedy operator), you can use either in-line sub-query or separated sub-query to get exact same result and run in exact same behaviour. The following two queries are examples. They run in exact same behaviour. Apparently the separated sub-query is more readable.
// in-line sub-query
var q1 = ds.Tables[1].AsEnumerable().Where(r1 => ds.Tables[0].AsEnumerable().Where(r2 => r2.Field("City").Equals("Toronto")).Select(r2 => r2.Field("AccountID")) .Contains(r1.Field("AccountID")));
// seperated sub-query
var q_sub = ds.Tables[0].AsEnumerable().Where(r => r.Field("City").Equals("Toronto")).Select(r => r.Field("AccountID")) ;
var q2 = ds.Tables[1].AsEnumerable().Where(r => q_sub.Contains(r.Field("AccountID ")));
1. outer join: In LINQ, the group join has similar function as outer join in SQL but not so powerful.
2. group by function: More convenient (easily getting key value) but only group by one key rather than by several fields as that in SQL. If you really need group by multi-fields, you can concatenate multi-fields as a group key. And LINQ’s groupby result is individual group objects rather than individual records as SQL.
3. Sub-query: Since most LINQ operators are lazy operators (execute until output result or run a greedy operator), you can use either in-line sub-query or separated sub-query to get exact same result and run in exact same behaviour. The following two queries are examples. They run in exact same behaviour. Apparently the separated sub-query is more readable.
// in-line sub-query
var q1 = ds.Tables[1].AsEnumerable().Where(r1 => ds.Tables[0].AsEnumerable().Where(r2 => r2.Field
// seperated sub-query
var q_sub = ds.Tables[0].AsEnumerable().Where(r => r.Field
var q2 = ds.Tables[1].AsEnumerable().Where(r => q_sub.Contains(r.Field