我的代码工作了一个多月,我的应用程序解析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