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

2023-12-08

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

我的 Windows Phone 应用程序中有一个数据库,其中包含ntext其中一个表中的字段,我试图向该字段写入一些内容,但我得到了InvalidOperationException带有消息:

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

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

我已经寻找解决方案,但找不到任何解决方案。

我发现我无法在 Windows Phone 上使用的唯一解决方案,因为它使用SqlConnection and SqlCommand with 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();

有谁知道有什么解决方法吗?

感谢您提前的答复!


我认为您在实际数据库文件中的列不是 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();
                }
            }
        }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Windows Phone 中的 SQL Server CE 中的 NTEXT 超过 4000 个字符 的相关文章

随机推荐