3

... it just doesn't work, at all. I've tried for days, with all different combinations of frick'n stuff and it won't budge.

There are certainly people out there who seem to be blogging about breezing through this sort of thing without seeing a glimpse of an issue saying things like "We all know that you can show public properties of extended EF classes by..." and "If you want to extend your data model to show a calculated field, simply..." - not so simple for me - arghghhhhghhhhhghh!!!

So, as per all of the typical examples, my EF partial 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;
    }
}

...I'm using a version of Dynamic Data Futures to get functionality like column ordering, better validation, etc, which is working fine. Have made a couple of adjustments to (e.g.) List.aspx.cs (shown above) and have changed the date formatting so as NZ style dates work on my US web-server. Other than that, everything's pretty standard, AFAIK.

My EF Models are housed in a separate assembly and am (obviously) extending some of the Entitys using partial classes. I just want to show two calculated bloody fields, but am having no success at all. I feel like I'm a new programmer bashing my head against a brick wall - none of the old tricks work. Programming shouldn't be this hard :-(

Someone, anyone, please help!!

Bernard.

4

2 回答 2

2

我不确定,但如果您使用的是 EF 3.5 SP1...

这意味着您的类派生自EntityObject,我怀疑动态数据是这种情况的特殊情况,并使用TypeDescriptionProvider知道如何从 中获取 EF 元数据的自定义,ObjectContext然后伪造必要的属性。

可能是问题的原因,因为这可能TypeDescriptionProvider只是将元数据用于 EF 知道的属性。这当然不包括您的计算属性。

我知道这不是一个“答案”,但希望它能为您指明正确的方向。

亚历克斯

于 2009-07-25T03:07:25.333 回答
0

使用 EF 时,分部类的命名空间必须与为您生成的分部类的命名空间匹配。在 Linq-2-SQL 版本中,生成的部分类没有命名空间,因此它可以正常工作。 http://forums.asp.net/t/1473192.aspx

于 2009-09-23T15:56:02.277 回答