2012-02-02 2 views
0

Я пытаюсь получить информацию из сгенерированного контекста данных umb, но всякий раз, когда я использую выражение linq, я получаю исключение, когда пытаюсь выполнить следующий код:Получение System.ArgumentNullException при попытке использовать linq для Umb

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; } 
} 
+0

Возможно, у вас есть некоторые недопустимые элементы, добавьте некоторые условия в umbContext.Products.Count() –

+0

Я уже решил это, но я не могу закрыть его, потому что с бонуса – Frederiek

+0

Как вы это сделали? –

ответ

1

это был пробл которые происходили раньше, и решение получало партизан, а затем и детям. Мы полагаем, что в базе данных есть какое-то значение, плавающее в базе данных

Смежные вопросы