Here is the code that I use. It is ado.net but it executes the fastest. Just cut and paste it in your custom functions, don't forget the proper usings.
public static string resolveUserId(object mUserId)
{
string userID = mUserId.ToString();
string resolvedUsername = "";
SqlDataReader rdr = null;
string connPath = WebConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString();
SqlConnection conn = new SqlConnection(connPath);
SqlCommand cmd = new SqlCommand("Select UserName FROM CMS_User where UserID = @UserID", conn);
SqlParameter paramProgramID = new SqlParameter() { ParameterName = "@UserID", Value = userID };
cmd.Parameters.Add(paramProgramID);
try
{
conn.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string UserName = (string)rdr["UserName"];
if (rdr["UserName"] != System.DBNull.Value)
{
resolvedUsername = UserName;
}
else
{
resolvedUsername = "";
}
}
}
finally
{
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
}
return resolvedUsername;
}