select a.ObjectFieldID,
a.FieldName,
b.RelationName
from tblMNG_Framework_ObjectField as a left join
tblMNG_Framework_ObjectRelation as b on a.ObjectID = b.RelatedObjectID
and a.ObjectFieldID = b.RelatedKeyFieldID
where a.ObjectID = 2
and a.Deleted = 0
Asked
Active
Viewed 98 times
-1

Dmitry Bychenko
- 180,369
- 20
- 160
- 215

Mustafa
- 9
- 6
-
1what are you asking? This already is an expression. Or do you mean method-syntax instead of SQL-like-syntax? – MakePeaceGreatAgain Mar 06 '20 at 08:17
-
@HimBromBeere I just want to this sql query convert to Linq LambdaExpression. – Mustafa Mar 06 '20 at 08:18
-
See Left outer join : https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause – jdweng Mar 06 '20 at 08:20
-
@jdweng thank you for your reply but this is Linq examples I want to linq lambda expression and I don't know How to make join include two and expression for example my example include join two criteria like this on a.ObjectID = b.RelatedObjectID and a.ObjectFieldID = b.RelatedKeyFieldID – Mustafa Mar 06 '20 at 08:23
-
Does this answer your question? [LEFT OUTER JOIN in LINQ](https://stackoverflow.com/questions/3404975/left-outer-join-in-linq) – Drag and Drop Mar 06 '20 at 08:30
-
1[LINQ to SQL: Left join on multiple columns](https://stackoverflow.com/questions/38431739/linq-to-sql-left-join-on-multiple-columns) – Drag and Drop Mar 06 '20 at 08:31
-
@DragandDrop Sorry, this is not the answer I am looking for.I want linq LAMBDAEXPRESSION.your answer is LINQ.thank you – Mustafa Mar 06 '20 at 08:36
-
[How do you perform a left outer join using linq extension methods](https://stackoverflow.com/questions/584820/how-do-you-perform-a-left-outer-join-using-linq-extension-methods). Note that my proposed dupe does include that already. – Drag and Drop Mar 06 '20 at 09:44
-
@Mustafa There is absolutely no difference between a linq query comprehension and a linq lambda expression. Why are you bent upon the lambda expression syntax? Is this some assignment? – Tanveer Badar Mar 06 '20 at 10:37
-
Perhaps my [SQL to Linq Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) might help you? Also, `GroupJoin` is the equivalent of `join`...`into`. – NetMage Mar 06 '20 at 20:03
1 Answers
0
It's my quick code, I have no data to test so feedback me with your data sample if left join is not exact.
tblMNG_Framework_ObjectField.GroupJoin(tblMNG_Framework_ObjectRelation,
a => new { JoinCol1 = a.ObjectID, JoinCol2 = a.ObjectFieldID },
b => new { JoinCol1 = b.RelatedObjectID, JoinCol2 = b.RelatedKeyFieldID },
(a, b) => new { a, b }).Where(x => x.a.ObjectID == 2 && x.a.Deleted == 0)
.SelectMany(b => b.b.DefaultIfEmpty(),
(a, b) => new { a.a.ObjectID, a.a.FieldName, b.RelationName });
Hope it helps

Tấn Nguyên
- 1,607
- 4
- 15
- 25
-
I get error like thi. The type arguments for method 'Enumerable.GroupJoin
(IEnumerable – Mustafa Mar 06 '20 at 09:04, IEnumerable , Func , Func , Func , TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. -
I have no data to test left join, so please if it's not work, provide a bit the data sample is ok – Tấn Nguyên Mar 06 '20 at 10:01
-
I get error like this : The type arguments for method 'Enumerable.GroupJoin
(IEnumerable – Mustafa Mar 06 '20 at 11:22, IEnumerable , Func , Func , Func , TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly -
It's work bro, check out my code here: https://dotnetfiddle.net/fId8qP – Tấn Nguyên Mar 09 '20 at 02:42
-
I still get error on GroupJoin syntax.I also compiled your code and there is no mistake :( thank your for everything – Mustafa Mar 09 '20 at 06:35
-
Yes you might check these references (System.Linq, System.Collections.Generic), these inputs as List, rebuild, clear caches,.... or even create a new console project one to make sure what the problem is. – Tấn Nguyên Mar 09 '20 at 07:05