How do I make a ManyToMany_Insert template for EF Dynamic Data?

假如想象 提交于 2019-12-13 03:35:38

问题


I'm extremely new to Dynamic Data, but I'll fire this off anyway.

I have an EF model set up, with a PJT table linking Shows and Genres. The EDMX correctly displays this as a * - * relationship between Shows and Genres, with navigation properties. Using Dynamic Data, I can create a Show item, but then only once it is created, can I edit it to link up the Genres (which are nicely displayed as check boxes).

I've read this http://blogs.msdn.com/b/davidebb/archive/2008/10/25/a-many-to-many-field-template-for-dynamic-data.aspx article which everyone refers to, but I can't see how to use the ManyToMany_Edit.ascx Field template on the Show insert page. Interestingly, in the ManyToMany_Edit.ascx.cs file that I have, there is a comment that says

// This field template is used both for Editing and Inserting

But I can't see it being used for inserting!

Any pointers would be greatly appreciated!


回答1:


For example, create such derived classes, change type of DefaultModel in Global.asax

public class MyMetaModel:MetaModel
{
     public MyMetaModel() : base()
     {
         this.FieldTemplateFactory = new MyFieldTemplateFactory();
     }

    protected override MetaTable CreateTable(System.Web.DynamicData.ModelProviders.TableProvider provider)
    {
        return new MyMetaTable(this, provider);
    }
}

public class MyMetaTable : MetaTable
{
    public MyMetaTable(MetaModel metaModel, TableProvider tableProvider)
        :base(metaModel, tableProvider)
    {
    }

    public override IEnumerable<MetaColumn> GetScaffoldColumns(System.Web.UI.WebControls.DataBoundControlMode mode, ContainerType containerType)
    {
        if (this.Name != "entity1set") return base.GetScaffoldColumns(mode, containerType);

        List<MetaColumn> result = new List<MetaColumn>();

        result.Add(this.GetColumn("Name"));
        result.Add(this.GetColumn("entity2"));  // this can be many to many column

        return result;
    }
}

best regards corporal_lael



来源:https://stackoverflow.com/questions/8476583/how-do-i-make-a-manytomany-insert-template-for-ef-dynamic-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!