So last couple of posts I have been talking about the new Dynamic Data features in .NET 3.5 SP1. Specifically I am talking about the dynamic scaffolding feature which automatically builds a CRUD operation page directly from the EDMX model. So last week I wrote a post on how to make certain tables readonly.
To reiterate, you would do something like this:
[ReadOnly(true)]
public partial class Course {
}
… and add the rest of the code discussed in my earlier post into your Global.asax. And Course would then become readonly. Unfortunately, if you do this you’ll all parent tables that has a relationship to the readonly table will no longer show a ForeignKey reference dropdown.
What that means is, if you have a table say Enrollment which has a many-to-many relationship to course, the dynamic data relationship manager is not going to give you a dropdown for all the course when you open up an enrollment, like it is supposed to. And the reason for this is that you’ve made the Course table readonly-which prevents FieldTemplate to pull up the ForeignKey_Edit.ascx template, so the ForeignKey.ascx comes up which is just a literal control.
It does not take consideration of the delete action in the table. Here is a work around that will take care of the delete action –
Create an additional page template (let’s say ReadOnly.aspx) based on List.aspx that doesn’t have any of edit/insert/delete functionalities and create an additional route like the following:
routes.Add(new DynamicDataRoute(\Employees/{action}.aspx\)
{
Action=\List\,
ViewName= \ReadOnly\,
Table = \Employees\,
Model = model
});