locked
fkColumn is null RRS feed

  • Question

  • User-1759624489 posted

     I have solved most of my problems but now I have another one.

     

      public partial class Autocomplete_Filter : FilterUserControlBase {
            protected void Page_Init(object sender, EventArgs e) {
                var fkColumn = Column as MetaForeignKeyColumn;

                //// dynamically build the context key so the web service knows which table we're talking about
                //autoComplete1.ContextKey = fkColumn.ParentTable.Provider.DataModel.ContextType.FullName + "#" + fkColumn.ParentTable.Name;
                autoComplete1.ContextKey = AutocompleteFilterService.GetContextKey(fkColumn.ParentTable);

     

    In that line, it says:

     

    System.NullReferenceException was unhandled by user code
      Message="Object reference not set to an instance of an object."
      Source="App_Web_7sz3if1_"
      StackTrace:
           at Autocomplete_Filter.Page_Init(Object sender, EventArgs e) in c:\Inetpub\wwwroot\WebSite\DynamicData\Filters\Autocomplete.ascx.cs:line 13
           at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
           at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
           at System.Web.UI.Control.OnInit(EventArgs e)
           at System.Web.UI.UserControl.OnInit(EventArgs e)
           at System.Web.UI.Control.InitRecursive(Control namingContainer)
           at System.Web.UI.Control.AddedControl(Control control, Int32 index)
           at System.Web.UI.ControlCollection.Add(Control child)
           at Microsoft.Web.DynamicData.DelegatingFilter.Page_Init(Object sender, EventArgs e) in D:\Luis\Sodexho\CDS Bancolombia\CdsBancolombia\CDSBancolombia\DynamicDataFutures0716\DynamicData\Futures\Controls\DelegatingFilter.cs:line 44
           at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
           at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
           at System.Web.UI.Control.OnInit(EventArgs e)
           at System.Web.UI.UserControl.OnInit(EventArgs e)
           at System.Web.UI.Control.InitRecursive(Control namingContainer)
           at System.Web.UI.Control.InitRecursive(Control namingContainer)
           at System.Web.UI.Control.AddedControl(Control control, Int32 index)
           at System.Web.UI.ControlCollection.Add(Control child)
           at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
           at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
           at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
           at System.Web.UI.WebControls.Repeater.DataBind()
           at System.Web.DynamicData.FilterRepeater.DataBind()
           at System.Web.DynamicData.FilterRepeater.Page_InitComplete(Object sender, EventArgs e)
           at System.EventHandler.Invoke(Object sender, EventArgs e)
           at System.Web.UI.Page.OnInitComplete(EventArgs e)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:

     

     

    I have the following code:

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.DynamicData;
    using System.Xml.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Data;
    using System.ComponentModel.DataAnnotations;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using Microsoft.Web.DynamicData;



    namespace Sodexo.Entities
    {
        [MetadataType(typeof(AssetMetaData))]
        public partial class Asset
        {
           
        }

        [DisplayName("Activo")]
        public class AssetMetaData
        {
            public object Id { get; set; }
           
            [DisplayName("Nombre Activo")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [Filter(FilterControl="Autocomplete")]
            public object Name { get; set; }

            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayName("Descripción Activo")]
           
            public object Description { get; set; }

            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayName("Marca")]
            public object Brand { get; set; }

            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayName("Modelo")]
            public object Model { get; set; }

            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayName("Serial")]
            public object Serial { get; set; }


            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayName("Ubicación")]
            public object Location { get; set; }

            [DisplayName("Sucursal")]
            public object Branch { get; set; }

            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayName("Capacidad")]
            public object Capacity { get; set; }

            [DisplayName("Tipo de Servicio")]
            public object ServiceType { get; set; }
        }
    }
    and this

                         <asp:AdvancedFilterRepeater ID="FilterRepeater" runat="server">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' AssociatedControlID="DynamicFilter$DropDownList1" />
                                <asp:DelegatingFilter runat="server" ID="DynamicFilter" OnSelectionChanged="OnFilterSelectedIndexChanged" />
                            </ItemTemplate>
                            <FooterTemplate><br /><br /></FooterTemplate>
                        </asp:AdvancedFilterRepeater>

    Friday, September 5, 2008 7:01 PM

All replies

  • User-330204900 posted

    Hi Levalencia, one of your columns must have a null value to get around this you will need to debug the AutocompleteFilter.asmx.cs webservice as i think this is where the error is occuring I think you will need to add a where clause to filter nulls [:D]

    Hope this helps [:D]

    Saturday, September 6, 2008 5:09 AM
  • User-1759624489 posted

    I dont think thats the problem. The problem is in the following line

     

       public partial class Autocomplete_Filter : FilterUserControlBase {
            protected void Page_Init(object sender, EventArgs e) {
                var fkColumn = Column as MetaForeignKeyColumn;

                //// dynamically build the context key so the web service knows which table we're talking about
                //autoComplete1.ContextKey = fkColumn.ParentTable.Provider.DataModel.ContextType.FullName + "#" + fkColumn.ParentTable.Name;
                autoComplete1.ContextKey = AutocompleteFilterService.GetContextKey(fkColumn.ParentTable);
     

     

         var fkColumn = Column as MetaForeignKeyColumn;
      

     

    becomes null

    Monday, September 8, 2008 10:43 AM
  • User-330204900 posted

    I dont think thats the problem. The problem is in the following line

     

       public partial class Autocomplete_Filter : FilterUserControlBase {
            protected void Page_Init(object sender, EventArgs e) {
                var fkColumn = Column as MetaForeignKeyColumn;

                //// dynamically build the context key so the web service knows which table we're talking about
                //autoComplete1.ContextKey = fkColumn.ParentTable.Provider.DataModel.ContextType.FullName + "#" + fkColumn.ParentTable.Name;
                autoComplete1.ContextKey = AutocompleteFilterService.GetContextKey(fkColumn.ParentTable);
     

     

         var fkColumn = Column as MetaForeignKeyColumn;
      

     

    becomes null

     

    Which become null fkColumn?

    Monday, September 8, 2008 11:06 AM
  • User-1759624489 posted

      var fkColumn = Column as MetaForeignKeyColumn;

    Monday, September 8, 2008 11:25 AM
  • User-797310475 posted

    The Autocomplete Filter from the Futures project was not designed to work with columns that are not foreign key columns. You would have to rewrite it to work with other column types.

    Monday, September 8, 2008 2:16 PM