Windows Phone 中 SQL Server CE 中超过 4000 个字符的 NTEXT [英] NTEXT with more than 4000 characters in SQL Server CE in Windows Phone

查看:25
本文介绍了Windows Phone 中 SQL Server CE 中超过 4000 个字符的 NTEXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

NTEXT with more than 4000 characters in SQL Server CE in windows phone

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

I have a database in my windows phone app with a ntext field in one of the tables, I'm trying to write some content to this field, but I get an InvalidOperationException with the message:

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

String truncation: max=4000, len=4621

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

I am trying to use ntext because I know that nvarchar doesn't accept more than 4000 chars.

我已经搜索了解决方案,但找不到任何解决方案.

I've searched for a solution but I couldn't find any.

我发现我无法在 windows phone 上使用的唯一解决方案,因为它使用 SqlConnectionSqlCommandSqlDbType.

The only solution I found I cannot use on windows phone, because it uses the 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();

有人知道任何解决方法吗?

Does anyone know any workaround?

感谢提前回答!!

推荐答案

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

I think your column in the actual database file is not ntext, for whatever reason.

这对我来说很好用:

    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();
                }
            }
        }

这篇关于Windows Phone 中 SQL Server CE 中超过 4000 个字符的 NTEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆