尝试使用linq到Umb时获取System.ArgumentNullException

时间:2012-02-02 14:38:49

标签: asp.net umbraco

我正在尝试从生成的umb数据上下文中获取信息,但每当我使用linq表达式时,当我尝试执行以下代码时会出现异常:

MyUmbracoDataContext umbContext = new MyUmbracoDataContext();
StringBuilder builder = new StringBuilder();
builder.Append(umbContext.Products.Count());
return builder.ToString();

例外:

System.ArgumentNullException:
  Value cannot be null.
Parameter name: attribute

  at System.Xml.Linq.XAttribute.op_Explicit(XAttribute attribute)

  at umbraco.Linq.Core.Node.NodeDataProvider.LoadFromXml[T](XElement xml, T node)

  at umbraco.Linq.Core.Node.NodeTree`1.GetEnumerator()

  at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)

  at XXX.XXX.Controls.Umbraco.usercontrols.ManageDealers.ToCsv(IEnumerable`1dealers)

生成的代码就像这样

public partial class Product : DocTypeBase, IProduct
    {
        public Product()
        {
        }
        private String _LinkedAccessories;
        /// <summary>
        /// Select the accessories that can be combined with this product
        /// </summary>
        [UmbracoInfo("linkedAccessories", DisplayName = "Linked accessories", Mandatory = false)]
        [Property()]
        [System.Runtime.Serialization.DataMemberAttribute()]
        public virtual String LinkedAccessories
        {
            get
            {
                return this._LinkedAccessories;
            }
            set
            {
                if ((this._LinkedAccessories != value))
                {
                    this.RaisePropertyChanging();
                    this._LinkedAccessories = value;
                    this.IsDirty = true;
                    this.RaisePropertyChanged("LinkedAccessories");
                }
            }
        }
        private String _ColumnName;
        /// <summary>
        /// 
        /// </summary>
        [UmbracoInfo("columnName", DisplayName = "Column name", Mandatory = true)]
        [Property()]
        [System.Runtime.Serialization.DataMemberAttribute()]
        public virtual String ColumnName
        {
            get
            {
                return this._ColumnName;
            }
            set
            {
                if ((this._ColumnName != value))
                {
                    this.RaisePropertyChanging();
                    this._ColumnName = value;
                    this.IsDirty = true;
                    this.RaisePropertyChanged("ColumnName");
                }
            }
        }
        private Int32? _Image;
        /// <summary>
        /// Image shown in the main slider
        /// </summary>
        [UmbracoInfo("image", DisplayName = "Homepage Slider Image", Mandatory = false)]
        [Property()]
        [System.Runtime.Serialization.DataMemberAttribute()]
        public virtual Int32? Image
        {
            get
            {
                return this._Image;
            }
            set
            {
                if ((this._Image != value))
                {
                    this.RaisePropertyChanging();
                    this._Image = value;
                    this.IsDirty = true;
                    this.RaisePropertyChanged("Image");
                }
            }
        }
        private Int32? _OverviewImage;
        /// <summary>
        /// Image shown on the overview page
        /// </summary>
        [UmbracoInfo("overviewImage", DisplayName = "Overview image", Mandatory = false)]
        [Property()]
        [System.Runtime.Serialization.DataMemberAttribute()]
        public virtual Int32? OverviewImage
        {
            get
            {
                return this._OverviewImage;
            }
            set
            {
                if ((this._OverviewImage != value))
                {
                    this.RaisePropertyChanging();
                    this._OverviewImage = value;
                    this.IsDirty = true;
                    this.RaisePropertyChanged("OverviewImage");
                }
            }
        }
        private Int32? _ProductDetailImage;
        /// <summary>
        /// Image shown on the product detail pages
        /// </summary>
        [UmbracoInfo("productDetailImage", DisplayName = "Product detail image", Mandatory = false)]
        [Property()]
        [System.Runtime.Serialization.DataMemberAttribute()]
        public virtual Int32? ProductDetailImage
        {
            get
            {
                return this._ProductDetailImage;
            }
            set
            {
                if ((this._ProductDetailImage != value))
                {
                    this.RaisePropertyChanging();
                    this._ProductDetailImage = value;
                    this.IsDirty = true;
                    this.RaisePropertyChanged("ProductDetailImage");
                }
            }
        }
        private String _RelatedTo;
        /// <summary>
        /// 
        /// </summary>
        [UmbracoInfo("relatedTo", DisplayName = "Related to", Mandatory = false)]
        [Property()]
        [System.Runtime.Serialization.DataMemberAttribute()]
        public virtual String RelatedTo
        {
            get
            {
                return this._RelatedTo;
            }
            set
            {
                if ((this._RelatedTo != value))
                {
                    this.RaisePropertyChanging();
                    this._RelatedTo = value;
                    this.IsDirty = true;
                    this.RaisePropertyChanged("RelatedTo");
                }
            }
        }
    }

public partial interface IProduct : IDocTypeBase
{
    String LinkedAccessories { get; set; }
    String ColumnName { get; set; }
    Int32? Image { get; set; }
    Int32? OverviewImage { get; set; }
    Int32? ProductDetailImage { get; set; }
    String RelatedTo { get; set; }
}

1 个答案:

答案 0 :(得分:1)

这是一个以前发生的问题,解决方案是获得parrent,然后是孩子。 我们认为数据库中存在一些浮动值