我的代碼工作了一個多月,我的應用程序解析RSS源(http://www.whitehouse.gov/feed/blog/white-house),並插入消息到DB:Wp的插入分貝例外
今天我當應用程序試圖添加該消息的」第一異常女士的盒子在2013年的狀態「的分貝。這裏是我的代碼:
News item = Query.instance().AddNews(channel.Guid, channel.Description, channel.Link, channel.PublishDate, channel.Title);
public News AddNews(string guid, string description, string link, DateTime publishDate, string title)
{
// create a new and add it to the context
News item = new News { Guid = guid, Description = description, Link = link, PublishDate = publishDate, Title = title };
// add the new to the context
db.NewsItems.InsertOnSubmit(item);
// save changes to the database
db.SubmitChanges();
return item;
}
Imade調試和問題是進入的消息(似乎lenght)的描述,這裏是個例外:
「類型的異常「系統.InvalidOperationException'發生在 Microsoft.Phone.Data.Internal.ni.dll中,並且在 託管/本機邊界之前未處理。 'System.InvalidOperationException'類型的第一次機會例外發生在 System.Data.Linq中。 ni.dll「
,這是列描述爲DB
private string _description;
[Column]
public string Description
{
get
{
return _description;
}
set
{
if (_description != value)
{
NotifyPropertyChanging("Description");
_description = value;
// Remove HTML tags.
_description = Regex.Replace(_description, "<[^>]+>", string.Empty);
// Remove newline characters
_description = _description.Replace("\r", "").Replace("\n", "");
// Remove encoded HTML characters
_description = HttpUtility.HtmlDecode(_description);
//replace spaces
_description = _description.Replace(" ", "");
//if (!string.IsNullOrEmpty(_description) && _description.Length > 3900)
// _description = _description.Substring(0, 3900);
NotifyPropertyChanged("Description");
}
}
}
當我去掉這一工作原理:
//if (!string.IsNullOrEmpty(_description) && _description.Length > 3900)
// _description = _description.Substring(0, 3900);
看來問題是描述字符串的長度 – 2013-02-13 10:05:59