I have an ASP NET project where I am using Entity to manage database queries, however I want to know how I can do an INNER JOIN between two tables with Entity, in this case the user table with type_access_user, I would like to return the name of the type_access_user in a query made in the user.
I’m new to C# and Entity Framework, I need help with this.
public class Type_access_user
{
[Key]
public int id { get; set; }
public string? name { get; set; }
public DateTime createdAt { get; set; }
public DateTime updatedAt { get; set; }
}
public class User
{
[Key]
public int id { get; set; }
public string? uid { get; set; }
public int? type_access_user_id { get; set; }
}
return await _context.User
.Select(user => new User
{
id = user.id,
uid = user.uid,
type_access_user_id = user.type_access_user_id,
createdAt = user.createdAt,
updatedAt = user.updatedAt,
})
.ToListAsync();
I need something similar to this query:
SELECT us.id,
us.uid,
us.type_access_user_id,
tyac.name AS type_access_user_name,
us.createdAt,
us.updatedAt
FROM User AS us
INNER JOIN Type_access_user AS tyac ON tyac.id = us.type_access_user_id