Locked History Actions

MyBlog/BlogEntry-2009-12-15

Entity Framework Dynamic Data Issues

Noodling around with Entity Framework and more specifically using it for ASP.NET Dynamic Data. By default if you have table(s) with a primary key column using "identity" for key generation. The insert/update views rendered by the Dynamic Data pages will show edit controls for your keys! This is a issue bug, but here is a fix. See http://forums.asp.net/t/1306469.aspx, and more specifically this blog entry for possible fixes. In my specific case I needed to add an attribute to the generated entity class as follows (note the ScoffoldColumn attribute). By the way, do this in a separate partial class file if you don't want to lose the change on regeneration of your model :)

        /// <summary>
        /// There are no comments for Property Id in the schema.
        /// </summary>
        [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        [global::System.ComponentModel.DataAnnotations.ScaffoldColumn(false)]
        public int Id
        {
            get
            {
                return this._Id;
            }

You'll also want to make note that even though Entity Framework supports many to many relationships (sorta), that Dynamic Data for VS2008 SP1 does not. This blog entry claims a solution. I need to dig into it yet.


CategoryEntityFramework