5

Instead of writing a linq query, is there a way I can just do a join 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 it practical? Also how do you use these predefined functions? I have a table called "Accounts" and "BankTransactions" they both have AccountId in common, How would I query that using these functions and what type of result would it return its one to many relationship.

1 Answer 1

11

LINQ is really your better bet, things start to get hectic in Lambda's really fast and linq just looks a lot better given the structured way compared to lambda's

See this SO 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 query that will return a collection of Accounts and inside each account it's relevant BankTransaction.

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

Edit: Just as an afterthought, you can add additional lamba extensions like a where clause to the above one.

Sign up to request clarification or add additional context in comments.

Comments

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.