I would like to use Entity Framework (EF) to query a SQL Server instance and return a list of database names on that instance.
I can do this using the following code, but wondered if there was a way with EF?
public static string[] GetDatabaseNames(SqlConnection masterConn)
{
List<string> databases = new List<string>();
// retrieve the name of all the databases from the sysdatabases table
using (SqlCommand cmd = new SqlCommand("SELECT [name] FROM sysdatabases", masterConn))
{
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
databases.Add((string)rdr["name"]);
}
}
}
return databases.ToArray();
}
I should mention that I am new to EF and its capabilities / limitations.