2

Windows phone 中 SQL Server CE 中超过 4000 个字符的 NTEXT

我的 Windows Phone 应用程序中有一个数据库,ntext其中一个表中有一个字段,我正在尝试向该字段写入一些内容,但我收到一条InvalidOperationException消息:

字符串截断:max=4000,len=4621

我正在尝试使用ntext,因为我知道它nvarchar不接受超过 4000 个字符。

我一直在寻找解决方案,但找不到任何解决方案。

我发现我无法在 Windows Phone 上使用的唯一解决方案,因为它使用SqlConnectionand SqlCommandwith SqlDbType.

以下是列的声明方式:

    private string _content;
    [Column(DbType="ntext")]
    public string Content
    {
        get
        {
            return _content;
        }
        set
        {
            if (value != _content)
            {
                _content = value;
                NotifyChange(o => o.Content);
            }
        }
    }

我将其插入:

cn.Articles.InsertAllOnSubmit(articlesToSave); 
cn.SubmitChanges();

有谁知道任何解决方法?

提前感谢您的回答!!

4

2 回答 2

3

我认为您在实际数据库文件中的列不是 ntext,无论出于何种原因。

这对我来说很好:

    using (NorthwindContext ctx = new NorthwindContext(NorthwindContext.ConnectionString))
    {
        ctx.DeleteDatabase();
        ctx.CreateDatabase();
        var category = new Categories();
        category.CategoryName = "Test";
        category.Description = new string('x', 6666);
        ctx.Categories.InsertOnSubmit(category);
        ctx.SubmitChanges();

        var testCat = ctx.Categories.First();
        if (testCat.Description.Length == 6666)
        {
            MessageBox.Show("Works on my Windows Phone");                
        }
    }

列声明:

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Description", DbType="NText", UpdateCheck=UpdateCheck.Never)]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                if ((this._Description != value))
                {
                    this.OnDescriptionChanging(value);
                    this.SendPropertyChanging();
                    this._Description = value;
                    this.SendPropertyChanged("Description");
                    this.OnDescriptionChanged();
                }
            }
        }
于 2012-07-06T18:25:52.457 回答
2

ntext 支持超过 5 亿个字符,因此您遇到的问题与它无关。请参阅http://msdn.microsoft.com/en-us/library/ms172424.aspx

您可能想查看以下内容:http: //msdn.microsoft.com/en-us/library/hh202872 (v=vs.92).aspx

该列表没有提到 ntext,但确实提到了 text。我猜您可能需要提供自己的自定义格式化程序。

更新

查看以下修补程序。它涵盖了使用 linq、ce 和 ntext 数据类型时的某些情况。看起来没有修复,格式化程序强制 ntext 成为引擎盖下的 nvarchar(4000) 。 http://support.microsoft.com/kb/958478

于 2012-07-06T16:19:02.187 回答