Dynamic data with Entity Framework ... using [ScaffoldColumn (true)] to show a public property via metadata

... it just doesn't work. I tried for several days, with all the different combinations of the freak, and it will not budge.

There are, of course, people who seem to be blogging about wading through such things without seeing a glimpse of a question that says, “We all know that you can show the public properties of the extended EF classes ...” and “If you want to expand your data model to show the calculated field, just ... "- not so easy for me - arghghhhhghhhhhhh !!!

So, in accordance with all typical examples, my EF-private class looks like this:

[DisplayColumn("Name")]
[MetadataType(typeof(SaleProduct_Metadata))]
public partial class SaleProduct
{        
    public string Test
    {
        get
        {
            return "blah";
        }
    }

    public class SaleProduct_Metadata
    {
        [ScaffoldColumn(true)] 
        public string Test;
    }
}  

My global.asax looks like this:

        MetaModel model = new MetaModel();
        model.RegisterContext(typeof(Sale.Models.SaleEntities), new ContextConfiguration() { ScaffoldAllTables = true });
        routes.Add(new DynamicDataRoute("DD/{table}/{action}.aspx")
        {
            Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
            Model = model
        });

And my List.aspx.cs looks like this:

public partial class List : System.Web.UI.Page
{
    protected MetaTable table;

    protected void Page_Init(object sender, EventArgs e)
    {
        //DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/);
        table = GridDataSource.GetTable();
        DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/);
        GridView1.ColumnsGenerator = new AdvancedFieldGenerator(table, true);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        table = GridDataSource.GetTable();
        Title = table.DisplayName;
        GridDataSource.Include = table.ForeignKeyColumnsNames;
        InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert);

        // Disable various options if the table is readonly
        if (table.IsReadOnly)
        {
            GridView1.Columns[0].Visible = false;
            InsertHyperLink.Visible = false;
        }
    }

    protected void OnFilterSelectedIndexChanged(object sender, EventArgs e)
    {
        GridView1.PageIndex = 0;
    }
}

... Dynamic Data Futures , , .., . (,) List.aspx.cs( ) , NZ - . , , AFAIK.

EF , () Entitys, . , . , , - . : - (

-, -, , !!

Bernard.

+3
2

, EF 3.5 SP1...

, EntityObject, , Dynamic Data TypeDescriptionProvider, , EF ObjectContext, .

, , , TypeDescriptionProvider , EF. , , .

, "", , , .

+2
0

Source: https://habr.com/ru/post/1713505/


All Articles