Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use asp.net dynamic data with Entity framework in another dll

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?


2 Answers

I was able to resolve this by forcing the load of the MetadataWorkspace and use an overload of the RegisterContext().

var context = new MyEntities();   // DataContext
context.MetadataWorkspace.LoadFromAssembly(typeof(MyEntity).Assembly); //  An EF Entity 
var config = new ContextConfiguration() {ScaffoldAllTables = true};
DefaultModel.RegisterContext(() => context, config);
like image 82
Jeff Lewis Avatar answered Nov 28 '25 04:11

Jeff Lewis


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/

like image 34
Josh Simerman Avatar answered Nov 28 '25 03:11

Josh Simerman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!