Entity Framework 4 + Self-Tracking Entities + Dynamic ASP.NET Data = Error

I am using the codegen parameter for Self-Tracking Entities in EF4 (VS2010 RC) and I am trying to use Dynamic Data to create a quick and dirty website for editing. Entities, Data Context, and EDMX files are 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 the full Lotta FAIL:

Could not find CLR type for "Core.Recording". in System.Data.Metadata.Edm.MetadataWorkspace.GetObjectSpaceType (StructuralType edmSpaceType) in System.Web.DynamicData.ModelProviders.EFDataModelProvider.GetClrTypeDetPremeterPremetPreventPreviewPriceTerms.DocumentPreview.Enterprise.TrendPreview ) in System.Web.DynamicData.ModelProviders.EFDataModelProvider..ctor (Object contextInstance, Func 1 contextFactory) at System.Web.DynamicData.ModelProviders.SchemaCreator.CreateDataModel(Object contextInstance, Func 1 contextFactory) in System.Web.Dame .RegisterContext (Func`1 contextFactory, ContextConfiguration configuration) in SimpleAdmin.Global.RegisterRoutes (RouteCollection routes) in D: \ SimpleAdmin \ Global.asax.cs: line 32 in SimpleAdmin.Global.Application_Start (object sender, EventArgs e) in D : \ SimpleAdmin \ Global.asax.cs: line 61

RegisterRoutes is as follows:

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

The default constructor in the Context has been changed 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 assume that I am referencing the O, C, or CS areas in the connection string incorrectly ... but everything works fine if I call the context in the code and use it. So what am I doing wrong?

Thanks!

+1
source share
3 answers

Actually, I found a workable solution. This is due to this post: http://thedatafarm.com/blog/data-access/wcf-data-services-and-ef-pocos-that-are-in-their-own-assembly/

Since I use the Dynamic Data site for a quick and dirty administrator, and not as a client production site, I don’t care about the performances that arose in the script. So I added a constructor that will only use DynamicData:

 public Entities(bool dynamicData) : base(ConfigurationManager.ConnectionStrings["Entities"].ConnectionString, ContainerName) { Initialize(); var tracestring = this.CreateQuery<Address>("Entities.Addresses").ToTraceString(); } 

then in the function RegisterRoutes Global.asax.cs now I have the following:

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

Works as directed. A kind of irritation. but on every platform there should be mods that don’t play well together, right?

NTN.

+1
source

You need to add a link to the assembly containing your entities in your web application.

+1
source

If you know an assembly containing POCO classes and having an ObjectContext, you can use the following to load information into metadata to avoid an error:

 objectContext.MetadataWorkspace.LoadFromAssembly(assemblyWithPocos); 
0
source

All Articles