The reason is that in the
Class
public class Connection
{
public static Social_NetwokingEntities GetContext()
{
Social_NetwokingEntities fdc = new Social_NetwokingEntities(ConfigurationManager.ConnectionStrings["FisharooConnectionString"].ToString());
return fdc;
}
}
the
GetContext
is declared as a
static
method, so it can be accessed through the
Type Connection
and not through the
instance
of the class
Connection
. Hence, the above error message is displayed.
Further, I think the following code may suffice instead of the second code block mentioned in the question
public Accounts GetAccountByID(int AccountID)
{
using (Social_NetwokingEntities dc = Connection.GetContext())
{
return dc.Accounts.FirstOrDefault(a => a.AccountID == AccountID);
}
}