1

Supposing i have 3 tables in the below picture that joined together. how can i access 'Email' field in 'Users' table in my query on 'UserReferralJoins' table ?

can any one help me?

var referalId = await _dbContext.UserReferrals.Where(x => x.UserId == CurrentUserId).Select(x => x.UserReferralId).FirstOrDefaultAsync();
        var list = await _dbContext.UserReferralJoins
            .Where(i => i.UserReferralId == referalId)
            .Select(x => new
            {
                Id = x.UserReferralJoinId,
                UserEmail = ???
                x.JoinDate
            }).ToListAsync(cancellationToken);

enter image description here

  • 2
    Please check the link https://stackoverflow.com/questions/21051612/entity-framework-join-3-tables . Should be helpful. – Sharath N S Jul 05 '22 at 11:38

2 Answers2

0

The name of field in your table is very important I see that your join field name is correct in your database as I see in picture very simply you can use linq query for fetching your purpose for example use 'userreferral'. user and fetch the field of user table. if you want more help plz comment me.

Mehrdad Noroozi
  • 620
  • 2
  • 13
0

Use this pattern in your select query

 UserEmail =x.UserReferral.ReferralCode
Mehrdad Noroozi
  • 620
  • 2
  • 13