NTEXT with more than 4000 characters in SQL Server CE in Windows Phone

别等时光非礼了梦想. 提交于 2019-11-30 16:28:19

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

This works fine for me:

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

Column declaration:

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

ntext supports over 500 million characters, so the problem you have has nothing to do with it. See http://msdn.microsoft.com/en-us/library/ms172424.aspx

You might want to look at the following: http://msdn.microsoft.com/en-us/library/hh202872(v=vs.92).aspx

The list doesn't mention ntext, but it does mention text. I'm going to guess that you might need to provide your own custom formatter.

update

Look at the following hotfix. It covers certain situations when using linq, ce and the ntext data type. Looks like without the fix, the formatter is forcing ntext to be a nvarchar(4000) under the hood. http://support.microsoft.com/kb/958478

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!