I have an ASP.NET 4 Dynamic Data web site that is running against a fairly simple set of database tables, exposed through an Entity Framework model in another assembly. I don't want to scaffold all of the tables in the EF model, so in my global.asax file, I've initialized the default model like this:
DefaultModel.RegisterContext( typeof( MyCompany.MyProject.DataModel.DataContext ), new ContextConfiguration() { ScaffoldAllTables = false } );
The MSDN docs (and the comments in the global.asax file) say that I should now be able to selectively enable scaffolding of individual tables by adding the [ScaffoldTable(true)]
attribute to their partial "buddy" class. I've done so like this:
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
namespace MyCompany.MyProject.DataModel
{
[MetadataType( typeof( InHouseClaimMetadata ) )]
[ScaffoldTable( true )]
public partial class InHouseClaim
{
[DisplayName( "In-House Claims" )]
[TableName( "In-House Claims" )]
public class InHouseClaimMetadata
{
[DisplayName( "Reporting Date" )]
public object ReportingDate { get; set; }
// etc etc...
}
}
}
But when loading Default.aspx, I get the following error message:
There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.
I've gotten this to work in similar scenarios before; the one thing that is different about this attempt is that my EF model is its own assembly. If I change the global.asax to go ahead and scaffold all tables, it works fine. But obviously, I don't want that. I was careful to make sure that the namespace for the partial metadata class matches the namespace of the EF data context.
So I'm stumped...
So, I'm an idiot: this isn't an EF or Dynamic Data problem, it is a C# constraint. From MSDN:
All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple modules.