I'm attempting to convert a multi table join to utilize the Entity Framework since I'm new to it. The first SQL had a similar appearance.
JOIN tab_NewsCommunities S1 ON S1.News_ID = tab_News.NewsID inner join tab_communities com on S1.Community_ID = com.Community_ID and com.RecordStatus_ID = 2 JOIN tab_Communities c ON S1.Community_ID = c.Community_ID JOIN tab_Favorites uf ON S1.Community_ID = uf2.Community_ID WHERE uf.[User_ID] = @UserId
This is the general appearance of the new Entity model after some simplification. Can somebody assist me with the SQL to LINQ or lambda conversion? Although there are many online examples, they are all single table joins. Thanks
You should read this blog entry by CRAIG STUNTZ, in my opinion. The concept is that you may choose all of your properties using the navigation link without using the JOIN operator as long as your model has the relevant relationships. Since your model can do it, why do it yourself? This is the true beauty of LINQ.
In the Include method of the most recent Entity Framework, a lamda expression is supported. You may then use a second choice to go further deeper into the connection.
var result = context.News.Include(x=>x.NewsCommunity.select(z=>z.Communities)).Where(...)