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; }
}
可能是你有一些無效的項目,給umbContext.Products.Count() – 2012-02-07 12:47:29
添加一些條件我已經解決了它,但是我不能關閉它,因爲沒有獎勵 – Frederiek 2012-02-07 13:08:26
你是怎麼做到的? – 2012-02-07 20:01:22