Hi Marco, I now get the same error as you in VS2008 and I am looking into it , it looks to me like the default constructor is being called regardless of the one used in the Global.asax.cs file.
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
public static void RegisterRoutes(RouteCollection routes)
{
MetaModel model = new MetaModel();
model.RegisterContext(() => new NorthwindModel.NorthwindEntities(getConStrIntegrated()),
new ContextConfiguration()
{
ScaffoldAllTables = true
});
// Routes omitted for clarity
}
Unfortunately, the current version of Dynamic Data doesn't support this approach with EF (L2S does work). To get the page templates to use the connection string you must add the following line to the Page_Load method in the page templates.
mtugnoli
Member
31 Points
55 Posts
Entity Framework: Entity Model in a separated dll
Jul 19, 2010 09:15 AM|LINK
I have a project where all Entity Models are in a separated dll,
to give a corrected connection in Global.asax I have add this :
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SqlClient";
entityBuilder.ProviderConnectionString = "server=myserver;database=mydb;Integrated Security=SSPI";
entityBuilder.Metadata = @"res://*";
OfficeBox.Settings.SystemEntities objContext = new OfficeBox.Settings.SystemEntities(entityBuilder.ToString());
model.RegisterContext(() => new OfficeBox.Settings.SystemEntities(entityBuilder.ToString()), new ContextConfiguration() { ScaffoldAllTables = true });
and seem run ok !! (on default page the gridview is filled with all my tables)
when click to one, this error occour :
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid."
How resolve this error ?
Thank You
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Entity Framework: Entity Model in a separated dll
Jul 19, 2010 10:12 AM|LINK
Hi , it seems to work for me have a look at my Global.asax.cs:
public class Global : System.Web.HttpApplication { private static MetaModel s_defaultModel = new MetaModel(); public static MetaModel DefaultModel { get { return s_defaultModel; } } public static void RegisterRoutes(RouteCollection routes) { EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(); entityBuilder.Provider = "System.Data.SqlClient"; entityBuilder.ProviderConnectionString = "server=aragorn;database=Northwind;Integrated Security=SSPI;MultipleActiveResultSets=True"; entityBuilder.Metadata = @"res://*"; var objContext = new NorthwindContext.NorthwindEntities(entityBuilder.ToString()); DefaultModel.RegisterContext(() => new NorthwindContext.NorthwindEntities(entityBuilder.ToString()), new ContextConfiguration() { ScaffoldAllTables = true }); routes.Add(new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }), Model = DefaultModel }); } void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } }Note that I tried it in an DD4 Web Application Project.
Dynamic Data
Always seeking an elegant solution.
mtugnoli
Member
31 Points
55 Posts
Re: Entity Framework: Entity Model in a separated dll
Jul 19, 2010 11:30 AM|LINK
Sorry Steve,
Give me same error..
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Entity Framework: Entity Model in a separated dll
Jul 19, 2010 12:09 PM|LINK
There must be an issue with the class library, are you using VS2010 or VS2008?
I can send my sample if you e-mail me using the Contact->Send sjnaughton an e-mail
Dynamic Data
Always seeking an elegant solution.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Entity Framework: Entity Model in a separated dll
Jul 20, 2010 09:52 AM|LINK
Hi Marco, I now get the same error as you in VS2008 and I am looking into it , it looks to me like the default constructor is being called regardless of the one used in the Global.asax.cs file.
Dynamic Data
Always seeking an elegant solution.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Entity Framework: Entity Model in a separated dll
Jul 20, 2010 10:01 AM|LINK
Hi Marco, have a look at this article by Rick Anderson here the pertinent part is quoted below
This is obviously something fixed in DD4 and .Net 4
Dynamic Data Explicit Connection Strings
Always seeking an elegant solution.
mtugnoli
Member
31 Points
55 Posts
Re: Entity Framework: Entity Model in a separated dll
Jul 20, 2010 11:15 AM|LINK
Thank You Steve !
It was a ConnectionString problem !!