public class Connection
{
public static string GetConecction()
{
return ConfigurationManager.ConnectionStrings["DCAssetEntities"].ConnectionString;
}
}
I have one “connection” class to configure my web with Entity framework model Entities
public class ConnectionDAL
{
private DCAssetEntities db;
public ConnectionDAL()
{
db = new DCAssetEntities(Connection.GetConecction());
}
}
then I intialize my database in “ConnectionDAL” class constructor,, It’s working good in Visusal Studio 2010 but in visusal Studio 2012 showing Error “DC_Asset_Maintenance.DAL.DCAssetEntities’ does not contain a constructor that takes 1 arguments
“
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Your class DCAssetEntities needs to have a constructor with the following definition.
public DCAssetEntities(string connectionString){}
Method 2
Make the constructor yourself in a partial class:
public partial class DCAssetEntities: DbContext
{
public DCAssetEntities(string connectionstring)
: base(connectionstring)
{
}
}
Related question:
Entity Connection String Constructor not found in EF 5 and WCF 4.5 at runtime
Method 3
You need to mark the constructor as public (or internal).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0