As Richard said above, the code should be:
public string GetUser()
{
var t = context.UsersTable.FirstOrDefault(x => x.Id == 2);
return t.Username;
}
Of course, this assumes you even have data in the UsersTable in your database AND it assumes there is a User in the UsersTable with an Id of 2.
This code also assumes that every row in the UsersTable in the database has a Username.
Your code also makes the assumption that an object is returned without checking for it. If there is no object returned from the database your return statement will throw a "NullReferenceExeception".
An updated version of the code:
public string GetUser(int userId)
{
var t = context.UsersTable.FirstOrDefault(x => x.Id == userId);
if (t == null)
{
return string.Empty;
}
else
{
return t.Username;
}
}