locked
Cannot determine table from data source RRS feed

  • Question

  • User-1063777375 posted
    Hello everyone,

    I'm trying to get simple Dynamic Data filtering to work with my existing project and I'm getting an unhandled exception. I installed the NuGet package (NotAClue.DynamicData.CustomFilters 1.2.1.2 and their prerequisites Extensions 1.2.1.1 and AjaxControlToolkit) - thank you sjnaughton!

    I created an Entity Data Model from a specific view in my database, along with a Navigation Property to a parent entity (to use the MultiForeignKey custom filter control by Steve).
    Here is the code I added in my Global.asax.cs file for Dynamic Data context registration:
    DefaultModel.RegisterContext(typeof(MyCentralEntities), new ContextConfiguration() { ScaffoldAllTables = false });
    Here is the markup I have in page in which I want Dynamic Data filtering:
    <asp:EntityDataSource ID="KioskContentEntityDs" runat="server"  ConnectionString="name=MyCentralEntities"  DefaultContainerName="MyCentralEntities" EnableFlattening="False"  EntitySetName="vUserKioskContents"></asp:EntityDataSource>
    
    <asp:QueryExtender TargetControlID="KioskContentEntityDs" ID="KioskContentQueryExt" runat="server">
    <asp:DynamicFilterExpression ControlID="KioskContentFilterRepeater" />
    </asp:QueryExtender>
    ...and just above my data repeater:
    <asp:QueryableFilterRepeater runat="server" ID="KioskContentFilterRepeater">
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="FilterLabel_PreRender" />
    <asp:DynamicFilter runat="server" ID="DynamicFilter" />
    <br />
    </ItemTemplate>
    </asp:QueryableFilterRepeater>
    Additionnally, I added a partial class to define the metadata of the table:
    using System.ComponentModel.DataAnnotations;
     
    namespace Models {
    [MetadataType(typeof(vUserKioskContent.Metadata))]
    public partial class vUserKioskContent {
    public class Metadata {
    [FilterUIHint("Contains")] public string CinemaName { get; set; }
    [FilterUIHint("MultiForeignKey")] public Country Country { get; set; }
    }
    }
    }

    As soon as I load that page, I get the following unhandled exception:
    "Cannot determine table from data source. Use the MetaTable.MapTable method to establish an association between a data source and a MetaTable instance."

    Stack Trace:
    [InvalidOperationException: Cannot determine table from data source. Use the MetaTable.MapTable method to establish an association between a data source and a MetaTable instance.]
    System.Web.DynamicData.DynamicDataExtensions.GetMetaTable(IDataSource dataSource, HttpContextBase context) +224473 System.Web.DynamicData.QueryableFilterRepeater.Page_InitComplete(Object sender, EventArgs e) +73
    System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Page.OnInitComplete(EventArgs e) +8960398
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +604

    In my PageInit, I tried to do a SetMetaTable on my data repeater (not the filter one) with
    KioskContentRepeater.SetMetaTable(Global.DefaultModel.GetTable("vUserKioskContents"));
     but the exception still occurs. If I check the object returned by Global.DefaultModel.GetTable("vUserKioskContents"), I see the 2 tables of my entity data model but none of them are "visible". What does that mean?

    Do you have an idea what I'm doing wrong? :\

    Thanks in advance for your help!
    Alex
    Wednesday, August 24, 2011 10:26 AM

Answers

  • User-1712241964 posted

    What has worked for me, when creating a fresh DD site utilizing EF, is using “%namespace%.%class%” in my global.asax registration statement.
    example:
    DefaultModel.RegisterContext(typeof(FBDBModel.FBDBEntities), new ContextConfiguration() { ScaffoldAllTables = true });

    Then, within my EntityDataSource on the page, add the ContextTypeName attribute.
    example:
    ContextTypeName="FBDBModel.FBDBEntities"

    (substitute your own model and class info, of course)

    -Gary

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 29, 2011 1:57 PM

All replies

  • User3866881 posted

    }Hello,

    Plz just remove the MetaDataType class out of its parent class and have a try——

    using System.ComponentModel.DataAnnotations;
     
    namespace Models
    {
    [MetadataType(typeof(vUserKioskContent.Metadata))]
    public partial class vUserKioskContent
    {
     //Here's your own properties...
     
    }


    public partial class Metadata
    {
    [FilterUIHint("Contains")] public string CinemaName { get; set; }
    [FilterUIHint("MultiForeignKey")] public Country Country { get; set; }
    }
    }

    Friday, August 26, 2011 1:04 AM
  • User-1063777375 posted

    Hello,

    I tried doing what you said, and even tried removing the metadata class altogether and I still get the same exception. :(

    Any other ideas?
    Thanks in advance. 

    Monday, August 29, 2011 1:39 PM
  • User1043796333 posted

    DefaultModel.RegisterContext(typeof(MyCentralEntities), new ContextConfiguration() { ScaffoldAllTables = false });

    Could it be your ScaffoldAllTables = false instead of true which is causing this?

    Monday, August 29, 2011 1:47 PM
  • User-1063777375 posted

    Same exception even when setting ScaffoldAllTables = true unfortunately. :(

    Thanks. 

    Monday, August 29, 2011 1:52 PM
  • User1043796333 posted

    Just to eliminate obvious things: are you using the same namespace everywhere?

    Monday, August 29, 2011 1:55 PM
  • User-1712241964 posted

    What has worked for me, when creating a fresh DD site utilizing EF, is using “%namespace%.%class%” in my global.asax registration statement.
    example:
    DefaultModel.RegisterContext(typeof(FBDBModel.FBDBEntities), new ContextConfiguration() { ScaffoldAllTables = true });

    Then, within my EntityDataSource on the page, add the ContextTypeName attribute.
    example:
    ContextTypeName="FBDBModel.FBDBEntities"

    (substitute your own model and class info, of course)

    -Gary

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 29, 2011 1:57 PM
  • User-1063777375 posted

    That was it! ContextTypeName attribute in my Entity DataSource markup!

    Thanks a lot! :) 

    Monday, August 29, 2011 2:18 PM