How to make a join in Entity Framework

Instead of writing a linq query, there is a way that I can just make a connection by simply doing something like this:

using (var db = new MatchGamingEntities()) { db.Accounts.Join() //I am unsure of the syntax db.Accounts.Include... ... return View(Account.SingleOrDefault()); } 

I want to use these predefined Entity functions instead of writing linq, is this practical? Also how do you use these predefined functions? I have a table called “Accounts” and “Bank Transactions”, they both have a common account AccountId. As I would request, using these functions, and what type of result will return its one-to-many relationship.

+4
source share
1 answer

LINQ is really your best bet, everything gets very busy in Lambda very quickly, and linq just looks a lot better considering the structured way compared to lambda's

See this post:

C # joins / where with Linq and Lambda

 var query = db.Accounts.Join(db.BankTransactions, acc => acc.AccountID, bank => bank.AccountID, (acc,bank) => new { Account = acc, BankTransaction = bank }); 

Edit: This should (or something similar) return a request that will return a collection of accounts, and within each account this applies to BankTransaction.

This should do it, but then again, rather use LINQ if possible.

Editing. Just like an afterthought, you can add additional lamba extensions, such as the where clause, to the previous one.

+5
source

Source: https://habr.com/ru/post/1344226/


All Articles