views:

714

answers:

2

how can i use asp.net dynamic data using EF in another dll and i dont want to put connection string in web.config or any config file. I have this code in Global.asax

model.RegisterContext(() => new MyObjectContext("entityconnectionString"), new ContextConfiguration() { ScaffoldAllTables = true });

the defalut page is ok but when i click on any table to see the details, I get this error: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. How can i solve this problem?

A: 

I am also having this problem. I'm using the Self-Tracking Entities codegen option in EF4 (VS2010 RC), and I'm trying to use Dynamic Data to build a quick-and-dirty website for editing. The Entities, Data Context, and EDMX files are all in separate assemblies, and this model works well when I call everything in code. But when I try to use it with Dynamic Data, right off the bat I get a whole lotta FAIL:

Could not find the CLR type for 'Core.Recording'. at System.Data.Metadata.Edm.MetadataWorkspace.GetObjectSpaceType(StructuralType edmSpaceType) at System.Web.DynamicData.ModelProviders.EFDataModelProvider.GetClrType(EntityType entityType) at System.Web.DynamicData.ModelProviders.EFDataModelProvider.CreateTableProvider(EntitySet entitySet, EntityType entityType) at System.Web.DynamicData.ModelProviders.EFDataModelProvider..ctor(Object contextInstance, Func1 contextFactory) at System.Web.DynamicData.ModelProviders.SchemaCreator.CreateDataModel(Object contextInstance, Func1 contextFactory) at System.Web.DynamicData.MetaModel.RegisterContext(Func`1 contextFactory, ContextConfiguration configuration) at SimpleAdmin.Global.RegisterRoutes(RouteCollection routes) in D:\SimpleAdmin\Global.asax.cs:line 32 at SimpleAdmin.Global.Application_Start(Object sender, EventArgs e) in D:\SimpleAdmin\Global.asax.cs:line 61

RegisterRoutes looks like this:

DefaultModel.RegisterContext((() =>  new DataContext.Entities()), new ContextConfiguration() { ScaffoldAllTables = true });

The default constructor on the Context has been modified to use my my connection string, which looks like this:

<add name="Entities" connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=xxxxxxxxxx;Initial Catalog=MyDB;Persist Security Info=True;User ID=xxxx;Password=xxxxxxx;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/> 

I imagine I'm not referencing the O, C, or CS spaces correctly in the connection string... yet it works just fine if I call the context up in code and use it. So what am I doing wrong?

Thanks!

interscape
A: 

I'm having the same problem. I have my EDMX data model file in one project called NW.DataModel. I added the code generation item for POCO objects, which I then moved off to a separate project called NW.Entities, so that they could be persistence ignorant. I have to tweak a few property settings for namespace generation in the Context object so that the Context would recognize the entities when building the solution. This was all fine, and I can use these projects in Console apps and a WCFdata service. Now I want to add a dynamic data site for some basic admin, and that's when the separate assemblies no longer play together. I'm just testing the project settings with the Northwind database.

I get this error: Could not find the CLR type for 'NWEntities.Shipper'.

This blog post seems to have some ideas, and links to forums where the issue has some recent activity, but no word from Microsoft yet.

http://thedatafarm.com/blog/data-access/wcf-data-services-and-ef-pocos-that-are-in-their-own-assembly/

Josh Simerman